Skip to content

fix(image): serve data: and blob: sources unoptimized and eager - #4725

Open
alcora-dev[bot] wants to merge 2 commits into
mainfrom
alcora/run_406u180y6q4u2e501b2i/fix/fix
Open

alcora-dev[bot] wants to merge 2 commits into
mainfrom
alcora/run_406u180y6q4u2e501b2i/fix/fix

Conversation

@alcora-dev

@alcora-dev alcora-dev Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #4724

When next/image gets a src starting with data: or blob:, it should render that URL unchanged, with no srcSet and no lazy default. Next.js 16.2.7 does this in get-img-props.js, and next/legacy/image has the same check. vinext sent these sources through /_next/image with a 1x/2x srcSet and set loading="lazy". So the browser asked the optimizer for a data: URL, and the image broke completely when middleware blocked /_next/image.

Root cause

ImageImpl in packages/vinext/src/shims/image.tsx and getImageProps in packages/vinext/src/shims/image-props.ts only skip the optimizer for unoptimized, global images.unoptimized, SVG, loader, remote and blocked sources. The loading ?? "lazy" default never checked the URL scheme. next/legacy/image wraps image.tsx, so it had the same problem.

Fix

  • New helper isDataOrBlobUrl in image-props.ts.
  • In both ImageImpl and getImageProps, a data:/blob: source now takes the existing unoptimized branch, so its src is passed through as-is: no optimizer URL, no srcSet, no custom loader. The lazy default is skipped for these sources. This matches Next.js isLazy = false, and loadingFinal = isLazy ? 'lazy' : loading: an explicit loading prop is still forwarded.
  • next/legacy/image gets the fix through image.tsx.

This deliberately leaves alone the !src (empty source) half of the same Next.js condition. It is a different input and nobody reported it. Nothing changes for other sources.

Behaviour

Scenario (data: or blob: src) Next.js 16.2.7 Before After
<Image> src / srcSet As-is, no srcSet /_next/image?url=data%3A…, 1x/2x srcSet As-is, no srcSet
<Image> default loading Not set lazy Not set
<Image loading="lazy"> lazy lazy lazy
<Image loader={…}> Loader not called, src as-is Loader URL Src as-is
<Image priority> No lazy, fetchPriority="high" eager + optimizer URL eager, src as-is
next/legacy/image As-is, eager Optimizer URL, lazy As-is, eager
getImageProps() As-is, loading undefined Optimizer URL, lazy As-is, loading undefined
Local /foo.png, remote, SVG — Unchanged Unchanged

The Next.js column comes from reading the installed node_modules/next 16.2.7 source: dist/shared/lib/get-img-props.js lines 269–274 and 550, and dist/client/legacy/image.js lines 519–523. No Next.js app was built, and .nextjs-ref was not available. With priority, vinext's existing loading="eager" (Next leaves loading unset) is a separate difference that this PR doesn't change.

Tests

tests/image-data-blob-src.test.ts, run for both data: and blob: sources:

  • <Image>: the rendered src is the input, with no /_next/image, no srcSet and no loading.
  • <Image>: an explicit loading="lazy" is kept.
  • <Image>: a custom loader is skipped.
  • next/legacy/image: the src is as-is and not lazy.
  • getImageProps(): the src is as-is, srcSet is undefined and loading is undefined, and an explicit loading is kept.

With image.tsx and image-props.ts restored to main, 8 of the 12 tests fail: every as-is/eager/loader/legacy case. The 4 explicit-loading tests pass on both, since they guard behaviour that was already right.

Validation

  • vp test run tests/image-data-blob-src.test.ts: 12 passed with the fix, and 8 failed / 4 passed without it.
  • vp test run tests/image-data-blob-src.test.ts tests/image-component.test.ts tests/image-optimization-parity.test.ts: 93 passed.
  • vp check: format, lint and type check all pass.

@alcora-dev

alcora-dev Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

clanky review

@alcora-dev

alcora-dev Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

/bigbonk review for issues
Please review exact head 756004cd997b928af4764c8e7541507830af517d without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

npm i https://pkg.pr.new/@vinext/cloudflare@4725

create-vinext-app

npm i https://pkg.pr.new/create-vinext-app@4725

@vinext/types

npm i https://pkg.pr.new/@vinext/types@4725

vinext

npm i https://pkg.pr.new/vinext@4725

@cloudflare/workers-response-store

npm i https://pkg.pr.new/@cloudflare/workers-response-store@4725

commit: 587c15b

@ask-bonk

ask-bonk Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Review: 1 findings.

Posted one actionable inline finding. Targeted tests pass: 93/93.

github run

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared 587c15b against base 10ac99c using alternating same-runner rounds. Next.js was unchanged and skipped.

0 improved · 0 regressed · 7 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 152.4 KB 152.4 KB ⚫ 0.0%
Client entry size (gzip) vinext 140.7 KB 140.7 KB ⚫ 0.0%
Dev server cold start vinext 2.93 s 2.91 s ⚫ -0.9%
Dev server cold start (large Pages Router app) vinext 26.06 s 26.16 s ⚫ +0.4%
Production build time vinext 3.88 s 3.85 s ⚫ -0.8%
RSC entry closure size (gzip) vinext 142.9 KB 142.9 KB ⚫ +0.0%
Server bundle size (gzip) vinext 250.6 KB 250.6 KB ⚫ -0.0%

View detailed results and traces

🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head

@github-actions

Copy link
Copy Markdown
Contributor
Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original
response-store-demo preview production
workers-cache preview production
kv preview production
static-assets-cache preview production
static-assets-pages preview production
static-assets-pages-i18n preview production
static-export preview production
web preview production

@alcora-dev

alcora-dev Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

/bigbonk review for issues
Please review exact head 587c15bb4c1cecfcc656594862816f1240810e18 without modifying or pushing the branch. Report all actionable findings within your 8-minute time limit.

@ask-bonk

ask-bonk Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Since last review: 1 resolved, 0 still open, 0 new.
LGTM!

github run

@clanky-the-clanker

Copy link
Copy Markdown

This pull request was not reviewed automatically because it was opened by a bot. A maintainer with write access can start a review by commenting clanky review (or clanker review or @clanky-the-clanker review), optionally followed by instructions (e.g. clanky review focus on the retry logic).

@alcora-dev

alcora-dev Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

clanky review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

next/image: serve data: and blob: sources unoptimized and eager, like Next.js

0 participants