Repository navigation
fix(image): serve data: and blob: sources unoptimized and eager - #4725
alcora-dev[bot] wants to merge 2 commits into
Conversation
|
clanky review |
|
/bigbonk review for issues |
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
|
Review: 1 findings. Posted one actionable inline finding. Targeted tests pass: 93/93. |
Performance benchmarksCompared 0 improved · 0 regressed · 7 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
|
|
/bigbonk review for issues |
|
Since last review: 1 resolved, 0 still open, 0 new. |
|
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 |
Fixes #4724
When
next/imagegets asrcstarting withdata:orblob:, it should render that URL unchanged, with nosrcSetand no lazy default. Next.js 16.2.7 does this inget-img-props.js, andnext/legacy/imagehas the same check. vinext sent these sources through/_next/imagewith a 1x/2xsrcSetand setloading="lazy". So the browser asked the optimizer for adata:URL, and the image broke completely when middleware blocked/_next/image.Root cause
ImageImplinpackages/vinext/src/shims/image.tsxandgetImagePropsinpackages/vinext/src/shims/image-props.tsonly skip the optimizer forunoptimized, globalimages.unoptimized, SVG, loader, remote and blocked sources. Theloading ?? "lazy"default never checked the URL scheme.next/legacy/imagewrapsimage.tsx, so it had the same problem.Fix
isDataOrBlobUrlinimage-props.ts.ImageImplandgetImageProps, adata:/blob:source now takes the existing unoptimized branch, so itssrcis passed through as-is: no optimizer URL, nosrcSet, no custom loader. The lazy default is skipped for these sources. This matches Next.jsisLazy = false, andloadingFinal = isLazy ? 'lazy' : loading: an explicitloadingprop is still forwarded.next/legacy/imagegets the fix throughimage.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
data:orblob:src)<Image>src/srcSetsrcSet/_next/image?url=data%3A…, 1x/2xsrcSetsrcSet<Image>defaultloadinglazy<Image loading="lazy">lazylazylazy<Image loader={…}><Image priority>fetchPriority="high"eager+ optimizer URLeager, src as-isnext/legacy/imagelazygetImageProps()loadingundefinedlazyloadingundefined/foo.png, remote, SVGThe Next.js column comes from reading the installed
node_modules/next16.2.7 source:dist/shared/lib/get-img-props.jslines 269–274 and 550, anddist/client/legacy/image.jslines 519–523. No Next.js app was built, and.nextjs-refwas not available. Withpriority, vinext's existingloading="eager"(Next leavesloadingunset) is a separate difference that this PR doesn't change.Tests
tests/image-data-blob-src.test.ts, run for bothdata:andblob:sources:<Image>: the renderedsrcis the input, with no/_next/image, nosrcSetand noloading.<Image>: an explicitloading="lazy"is kept.<Image>: a custom loader is skipped.next/legacy/image: thesrcis as-is and not lazy.getImageProps(): thesrcis as-is,srcSetis undefined andloadingis undefined, and an explicitloadingis kept.With
image.tsxandimage-props.tsrestored tomain, 8 of the 12 tests fail: every as-is/eager/loader/legacy case. The 4 explicit-loadingtests 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.