Skip to content

fix(image): fix custom-loader srcSet, support images.loaderFile - #3686

Open
AhmedElBanna80 wants to merge 26 commits into
cloudflare:mainfrom
AhmedElBanna80:fix/c3-image-shim-trailing-slash-srcset
Open

AhmedElBanna80 wants to merge 26 commits into
cloudflare:mainfrom
AhmedElBanna80:fix/c3-image-shim-trailing-slash-srcset

Conversation

@AhmedElBanna80

@AhmedElBanna80 AhmedElBanna80 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Two gaps in next/image compared with Next.js (a third, trailingSlash for the built-in loader, is now on main and was removed from this PR):

  1. A custom loader prop produced no srcSet and forced quality to 75. The component and getImageProps() called the loader once, with the intrinsic width (or 0 for fill) and quality ?? 75. Next.js runs a custom loader through the same generateImgAttrs as the built-in loader. That means 1x/2x widths, sizes-derived widths, or every device size plus sizes="100vw" for fill, and quality passed through as given (including undefined). Other loader-path details now also follow getImgProps:

    • overrideSrc replaces src but keeps the loader's srcSet.
    • Empty, data: and blob: sources are unoptimized, so they never reach a loader or /_next/image. This applies to the built-in loader and next/legacy/image too.
    • A caller-supplied srcSet is dropped.
    • src comes after srcSet/sizes.
    • The loader path keeps the same priority, data-nimg and blur handling as the other paths.
  2. images.loaderFile had no effect. next/image (the component and getImageProps()) now falls back to the user's loader file when no loader prop is given. The plugin aliases the slot vinext/shims/image-loader-file, which exports undefined by default, to the user's file, the same way Next.js aliases next/dist/shared/lib/image-loader. The rules are ported from Next.js's server/config.ts and getImgProps:

    • loaderFile applies when images.loader is unset, "default" or "custom". The path is path.joined onto the project root.
    • Combining it with imgix/cloudinary/akamai throws, and so does a missing file. Both use Next.js's messages.
    • A file without a default export throws images.loaderFile detected but the file is missing default export.
    • images.loader: "custom" with no loaderFile throws Image with src "..." is missing "loader" prop. for images that have no loader prop.
    • next/legacy/image does not use the loader file, as in Next.js. With loader: "custom" it throws only for optimized images.

The loader file is applied inside the shared shim (image-props.ts for getImageProps(), image.tsx for the component), on top of the server-safe split that main now has, so it also works from Server Components. One difference from Next.js: the loader file module is imported by image-props.ts, so a legacy-only page evaluates it too, even though next/legacy/image never calls it.

Testing

  • tests/e2e/static-export/images.spec.ts (Playwright, static-export project) runs against the checked-in tests/fixtures/static-export fixture. The fixture sets images.loaderFile, which is Next.js's documented next/image setup for output: "export". Its /images/ page renders next/image with the loader file (fixed size, fill and overrideSrc), next/image with a loader prop, and next/legacy/image on the built-in loader. The spec checks src, srcset and sizes in the browser after hydration, and ports cases from Next.js's next-image-new/loader-config tests. On the current head all 3 pass; with the loader-file fallback removed from withConfiguredLoader, the loader-file case fails. The fixture lists ipaddr.js because pnpm doesn't hoist vinext's copy.
  • tests/image-loader-file.test.ts covers the config hook's alias and validation.
  • tests/image-component.test.ts and tests/shims.test.ts cover the shim behaviour. Two existing assertions that encoded the old single-width, quality-75 loader output were updated.
  • After merging current main: vp check, sync-next-types --check and check-shim-types are clean, and the image, shim, alias and trailing-slash unit files pass (1618 tests).

Not changed

next/legacy/image layout semantics and images.path/basePath for the built-in loader are unchanged from main.

…ages.loaderFile

next/image had three related gaps against Next.js's documented behavior:

- imageOptimizationUrl() always emitted `/_next/image?...`, ignoring
  `trailingSlash: true`. Next.js emits `/_next/image/?...` in that case.
  Both the App Router and legacy Image shims share this helper, so both
  were affected.

- A custom `loader` prop was called once with the intrinsic width and a
  forced quality of 75, producing a single `src` with no `srcSet`. Next.js
  gives a custom loader the same per-breakpoint treatment as the built-in
  loader: both the 1x and 2x (or sizes-derived) candidate widths, and the
  `quality` prop passed through as given (including `undefined`, letting
  the loader apply its own default) rather than forced to 75.

- `images.loaderFile` was parsed but never wired up anywhere, so it had no
  effect. It's now resolved via a `resolve.alias` entry (aliasing the bare
  specifier `vinext:image-loader-file` to the configured file, or to a
  no-op default when unset) that the Image shim imports unconditionally
  and falls back to when no per-image `loader` prop is given.

Fixes two of next/image's existing unit tests that had encoded the old
(incorrect) custom-loader behavior, and adds coverage for all three fixes.
@pkg-pr-new

pkg-pr-new Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vinext/cloudflare

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

create-vinext-app

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

@vinext/types

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

vinext

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

@cloudflare/workers-response-store

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

commit: ad41a5f

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Performance benchmarks

Compared ad41a5f against base 8659957 using alternating same-runner rounds. Next.js was unchanged and skipped.

1 improved · 1 regressed · 5 within ±1.5%

Scenario Framework Baseline Current Change
Client bundle size (gzip) vinext 152.3 KB 152.4 KB ⚫ +0.0%
Client entry size (gzip) vinext 140.6 KB 140.7 KB ⚫ +0.1%
Dev server cold start vinext 2.23 s 2.20 s 🟢 -1.7%
Dev server cold start (large Pages Router app) vinext 18.45 s 18.32 s ⚫ -0.7%
Production build time vinext 2.71 s 2.76 s 🔴 +1.6%
RSC entry closure size (gzip) vinext 142.6 KB 142.8 KB ⚫ +0.2%
Server bundle size (gzip) vinext 250.2 KB 250.5 KB ⚫ +0.1%

View detailed results and traces

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

AhmedElBanna80 and others added 2 commits October 4, 2026 11:26
…eakpoint srcSet

tests/shims.test.ts has its own, separate custom-loader coverage for
next/image that duplicates (but doesn't share with) tests/image-component.test.ts
— it still pinned the old single-width/quality-75 behavior this PR
replaced. Bring it in line with the per-breakpoint treatment: src is
the 2x candidate, srcSet carries both 1x and 2x, and quality passes
through as given (undefined here, since neither test sets a quality
prop).
…h Next.js rules

- Import the loaderFile slot as vinext/shims/image-loader-file so unit tests
  resolve it through the existing vinext/shims alias; drop the root
  vite.config.ts alias, the ambient .d.ts and the check-shim-types hook.
- Keep that specifier bare in dist so the plugin alias still applies.
- Apply loaderFile when images.loader is unset, default or custom, and throw
  Next.js's errors for other loaders or a missing file.
- Skip remotePatterns validation in getImageProps when a custom loader owns
  the URL, as the component path and Next.js do.
- Add dev-server fixture tests for trailingSlash, loader-prop srcSet and
  images.loaderFile.
@james-elicx

Copy link
Copy Markdown
Member

Maintainer update (pushed 7f7f69c on top of your commits):

  • Root vite.config.ts alias removed. shims/image.tsx now imports the loaderFile slot as vinext/shims/image-loader-file (a real shim module exporting undefined). Unit tests resolve it through the existing vinext/shims alias, so the extra root alias, virtual-vinext-image-loader-file.d.ts, and the check-shim-types.mjs hook are gone. The vinext plugin aliases that specifier to the user's file. packages/vinext/vite.config.ts keeps the specifier bare in dist. Without that, vp pack rewrites it to ./image-loader-file.js and constant-folds the undefined default, so loaderFile would never apply in the published package.

  • loaderFile rules now match Next.js (server/config.ts). loaderFile applies when images.loader is unset, "default" or "custom". Previously it required "custom", but Next applies { images: { loaderFile } } on its own. vinext now throws Next's errors when loaderFile is combined with another loader preset or the file doesn't exist.

  • getImageProps no longer runs remotePatterns validation when a custom loader (prop or loaderFile) owns the URL. This matches the component path and Next.js, where validation only happens in the default loader.

  • Fixture tests: tests/image-optimization-parity.test.ts (a dev server on a copy of app-basic) now covers three cases:

    • trailingSlash: true emits /_next/image/?url=…, and that URL reaches the image endpoint without a 308.
    • A loader prop gets the 1x/2x srcSet and an unset quality.
    • images.loaderFile is a port of Next's loader-config dummy loader.

    Without the source changes, all three fail:

    • expected '/_next/image?url=%2Fhello%20world.png…' to be '/_next/image/?url=…'
    • the loader-prop src/srcSet mismatch
    • expected '/_next/image?url=…' to be '/hello world.png#w:128,q:50'

    With the changes, all 10 tests in the file pass.

@james-elicx

Copy link
Copy Markdown
Member

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

@ask-bonk

ask-bonk Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

error: Your local changes to the following files would be overwritten by checkout:
pnpm-lock.yaml
Please commit your changes or stash them before you switch branches.
Aborting

github run

@ask-bonk

ask-bonk Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

@james-elicx Bonk workflow timed out.

View workflow run · To retry, trigger Bonk again.

@james-elicx

Copy link
Copy Markdown
Member

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

@ask-bonk

ask-bonk Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

error: Your local changes to the following files would be overwritten by checkout:
pnpm-lock.yaml
Please commit your changes or stash them before you switch branches.
Aborting

github run

@james-elicx

Copy link
Copy Markdown
Member

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

Comment thread packages/vinext/src/shims/image.tsx Resolved
Comment thread packages/vinext/src/index.ts Resolved
Comment thread packages/vinext/src/shims/image.tsx Resolved
@ask-bonk

ask-bonk Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for runner@runnervm8df0l.3drbd0fvkhmelegyphvzhhcaub.bx.internal.cloudapp.net) not allowed

github run

… and custom mode

- Give width-less (fill) images every device width and sizes=100vw when a
  custom loader or loaderFile is in effect, as Next.js getWidths() does.
- Apply overrideSrc over the loader-generated src in both Image and
  getImageProps.
- Throw Next.js's missing-loader error when images.loader is "custom" and an
  image has neither a loader prop nor a loaderFile, and its missing default
  export error for an empty loaderFile.
@james-elicx

Copy link
Copy Markdown
Member

Bonk round 1 addressed in 8323621:

  1. fill + custom loader/loaderFile (image.tsx:628, getImageProps): fixed. Width-less images now get every device size as w candidates, with sizes="100vw" when no sizes is given, matching Next's getWidths(config, undefined, sizes). The sizes branch still runs first. Tests: unit gives a fill image's custom loader every device width and sizes=100vw (component + getImageProps), and fixture gives fill images every device width and honors overrideSrc (loaderFile server). Without the fix the fixture fails with expected '/hello world.png#w:0,q:50' to be '/hello world.png#w:3840,q:50'.
  2. images.loader: "custom" without a loader prop or loaderFile (index.ts:1322): fixed. A new __VINEXT_IMAGE_CUSTOM_LOADER define makes the shim throw Next's Image with src "…" is missing "loader" prop. error before the unoptimized branch, in both APIs, as getImgProps does. For the same check order, a __VINEXT_IMAGE_LOADER_FILE define also makes the shim throw Next's images.loaderFile detected but the file is missing default export. error when the configured file has no default export. Tests: unit images.loader config validation and the define assertions in tests/image-loader-file.test.ts.
  3. overrideSrc with a configured loader (image.tsx:624): fixed. src is now overrideSrc || loaderSrc and the loader srcSet is kept, in both the rendered and preloaded src and in getImageProps. Tests: unit applies overrideSrc on top of custom loader attributes, plus the fixture assertion above.

All the new tests fail on the previous head and pass now. vp check and check-shim-types are clean.

@james-elicx

Copy link
Copy Markdown
Member

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

Comment thread packages/vinext/src/shims/image.tsx Resolved
Comment thread packages/vinext/src/shims/image.tsx Resolved
Comment thread packages/vinext/src/shims/image.tsx Resolved
@ask-bonk

ask-bonk Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for runner@runnervm8df0l.ylsntxfoq4iuxizsmqxnehi3ne.dx.internal.cloudapp.net) not allowed

github run

… srcSet

- Treat data: and blob: sources as unoptimized when a custom loader or
  loaderFile is in effect, as Next.js does, so the loader never sees them.
- Order src after srcSet/sizes in the custom-loader <img> and in the
  getImageProps() result, matching Next.js's Safari-motivated prop order.
@james-elicx

Copy link
Copy Markdown
Member

Bonk round 2 addressed in db8b569:

  1. data:/blob: sources with a custom loader (image.tsx:665): fixed. When a loader (prop or loaderFile) is in effect, these sources take the existing unoptimized path in both Image and getImageProps(), so the loader is never called and no srcSet is emitted. This matches Next's unoptimized = true before generateImgAttrs. Test: unit never passes data: or blob: sources to a custom loader asserts the loader vi.fn is never called. It fails on the previous head.
  2. Attribute order (image.tsx:689): fixed. In the custom-loader <img> and in the getImageProps() result object, src now comes after srcSet/sizes, matching Next's prop order. Test: unit orders src after srcSet and sizes for custom loaders (SSR attribute order + Object.keys order). It fails on the previous head.
  3. next/legacy/image layout semantics (image.tsx:668): declined as out of scope for this PR. shims/legacy-image.tsx is a thin wrapper that already maps layout="responsive" and fixed/intrinsic+sizes the same way for the default loader on main: x-descriptors for responsive, and w candidates when sizes is passed. The custom-loader path now shares that existing behavior. Before this PR, custom loaders got no srcSet at all, which also diverged from Next legacy. Porting legacy getWidths (layout-aware width selection, and ignoring sizes for fixed/intrinsic while still emitting the attribute) means reworking the legacy shim for both loaders. That's a separate change and has been flagged to the maintainer.

vp check is clean, and the targeted unit and fixture tests pass.

@james-elicx

Copy link
Copy Markdown
Member

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

Comment thread packages/vinext/src/index.ts Resolved
Comment thread packages/vinext/src/shims/image.tsx Resolved
Comment thread packages/vinext/src/shims/image.tsx Resolved
@ask-bonk

ask-bonk Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for runner@runnervm8df0l.sgyfafs2kbnexlihx1gfup2jfd.cx.internal.cloudapp.net) not allowed

github run

…image

- Join images.loaderFile onto the project root like Next.js, so a leading
  slash stays project-relative instead of pointing at the filesystem root.
- Import the loader file as a namespace so a file without a default export
  reaches Next.js's missing-default-export error instead of failing to link
  (the browser) or to bundle (rolldown).
- Keep next/legacy/image on its built-in loader: it never reads loaderFile,
  and its custom-mode error only fires for optimized images, as in Next.js.
@james-elicx

Copy link
Copy Markdown
Member

Bonk round 3 addressed in b27f365:

  1. path.resolve vs path.join (index.ts:1329): fixed. The plugin now uses path.join(root, loaderFile) like Next's server/config.ts, so "/dummy-loader.ts" is project-relative. Test: unit treats a leading-slash loaderFile as project-relative, which fails on the previous head. The named-export fixture below also uses a leading-slash path.
  2. Loader file with only named exports (image.tsx:31): fixed. The shim now uses a namespace import and reads .default, so Next's images.loaderFile detected but the file is missing default export. error is thrown instead of a link failure. I also checked rolldown directly: a static default import of a module without a default fails the build, while namespace .default access builds with only a warning. Test: fixture reports Next.js's missing default export error, a port of test/e2e/app-dir/loader-file-named-export-custom-loader-error with loaderFile: "/named-loader.mjs". It expects a 500 with that message.
  3. loaderFile leaking into next/legacy/image (image.tsx:445): fixed. legacy-image.tsx now marks its inner Image as legacy, and legacy images ignore images.loaderFile. Legacy images in images.loader: "custom" mode now throw the missing-loader error only for optimized images, matching Next legacy's customLoader, which only throws when asked for a URL. Tests: fixture leaves next/legacy/image on the built-in loader (loaderFile server) and unit keeps next/legacy/image off loaderFile and lets unoptimized images through. Both fail on the previous head.

vp check, check-shim-types, and the targeted unit and fixture tests (13/13 in image-optimization-parity) all pass.

@james-elicx

Copy link
Copy Markdown
Member

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

@ask-bonk

ask-bonk Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: empty ident name (for runner@runnervm8df0l.ybwjd3tuk2wenjvznezyc2abqa.jx.internal.cloudapp.net) not allowed

github run

… images

Next.js applies fetchPriority, data-nimg and the blur placeholder background
independently of which loader produced the URL; the custom-loader branch
(loader prop or images.loaderFile) dropped all three.
@ask-bonk

ask-bonk Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Review: 2 findings.

Posted both findings inline.

github run

…mage

Next.js's getImgProps and next/legacy/image mark these sources unoptimized
before building any URL. vinext only did that when a custom loader was
present, so next/legacy/image under images.loader: "custom" (and the
built-in loader generally) emitted /_next/image?url=data%3A... instead.

Also make the static-export image spec fail on any console or page error,
so production's minified hydration errors are caught.
@james-elicx

Copy link
Copy Markdown
Member

Addressed both bonk findings in 9445847:

  • Inline sources under images.loader: "custom" (image.tsx): unoptimized is now unoptimizedProp || isInlineSrc(src) in both the component and getImageProps, so empty, data: and blob: sources never reach a loader or /_next/image. This matches getImgProps and next/legacy/image, which mark them unoptimized before building a URL. New unit tests: next/legacy/image in custom mode renders data:/blob: sources as-is, and next/image renders inline sources as-is with and without a loader prop. Both fail on the previous head (<img src="/_next/image?url=data%3A…">) and pass now.
  • Hydration listener (images.spec.ts): the spec now fails on every console error and page error, not just ones that mention "hydrat". The only exception is the fixture's image URLs failing to load, since the static host has no image files or optimizer. I checked that it catches errors by temporarily adding a client-side console.error to the fixture: all 3 tests failed. The spec passes locally against the built static export.

@james-elicx

Copy link
Copy Markdown
Member

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

@ask-bonk

ask-bonk Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

LGTM!

github run

Legacy responsive images get every device width with w descriptors and sizes=100vw, and fixed/intrinsic images keep 1x/2x candidates even when given sizes, matching getWidths() in Next.js's client/legacy/image.tsx.
@clanky-the-clanker

Copy link
Copy Markdown

This pull request was not reviewed automatically because its author does not have write access to this repository. 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).

BetoFrega added a commit to BetoFrega/tudo-macae that referenced this pull request Oct 24, 2026
Sem issue: requer o rótulo `no-issue`. Sucede #50.

## O quê

- `src/components/ui/image.tsx` é o único ponto de importação de
`next/image` no app. No `next build` ele só reexporta `next/image`, que
já respeita `images.loaderFile` e monta o srcset.
- `vite.vinext.config.ts` deixa de criar alias para `next/image` e troca
`@/components/ui/image` por `web-worker/image.tsx`, que agora importa
`next/image` normalmente. O módulo exporta nomes explícitos em vez de
`export *`, porque o `@vitejs/plugin-rsc` não lê do disco o módulo
virtual `next/image` do vinext para expandir um `export *` com `"use
client"`.
- Os seis componentes que usavam `next/image` passam a importar o módulo
do app. Uma regra `no-restricted-imports` barra `next/image` em `src/` e
`web-worker/` fora dos dois módulos.
- As regras do Playwright foram, sem mudança, para
`eslint.playwright.mjs`, porque `eslint.config.mjs` já estava no limite
de 300 linhas do `max-lines`.
- `vinext` ^1.3.0 e `@vinext/cloudflare` ^1.2.0 (exatos em
`apps/web-workers`), com lockfile pelo `npm install`. O hold do
Dependabot sai.
- `@expires 2026-12-24` no wrapper: apagar quando o vinext respeitar
`images.loaderFile` e o srcset de loader customizado
(cloudflare/vinext#3686).

## Por quê

Desde cloudflare/vinext#4055 (1.3.0), fora do ambiente `rsc` o vinext
resolve `vinext/shims/image` via `this.resolve("next/image")`. Com o
nosso alias global de `next/image`, o wrapper importava a si mesmo e
`<Image>` renderizava `<Image>` sem fim. O Worker web estourava memória
e CPU em toda página, e o `www` ficou em 502 até a #50 voltar o vinext
para 1.0.1. Reportado em cloudflare/vinext#4262. Sem o alias de
`next/image`, o vinext resolve o próprio shim como foi projetado.

## Verificação

- Bundle de produção do vinext no commit final
(`CLOUDFLARE_ENV=production … vite build --config vite.vinext.config.ts`
+ `wrangler dev -c dist/server/wrangler.json --local`): `/` 200 em 0,66
s, `/termos-e-condicoes` 200 em 0,09 s e `/noticias` 200 em 0,04 s,
todos com `</html>`. No chunk SSR, o wrapper renderiza o shim do vinext,
não a si mesmo.
- E2E com `E2E_RENDERER=vinext` e com o renderer Next, 5/5 em cada:
`ads/ad-with-photo`, `advertiser-profile/photo-upload`, `admin/blog`,
`navigation/mobile-menu-navigation` e `legal/terms-navigation`. As rotas
de foto de classificados devolvem 400 para larguras fora do conjunto
configurado, então os dois primeiros cobrem o srcset do loader.
- `npm run typecheck`, `typecheck:worker`, ESLint, `check:harness`,
`lint:boundaries`, `build:check`, testes unitários dos componentes de
imagem (28 arquivos, 107 testes), `vitest.worker.config.mts` (26
arquivos, 408 testes) e `git diff --check`.
- A coleção E2E completa não foi rodada aqui. O deploy roda essa
coleção, mas no renderer Next.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01C2S56fDP1aqvpDKFZ41s2Q)_

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Touches production Cloudflare Worker rendering and
responsive/classifieds image URLs; regression risk is mitigated by the
alias change and targeted E2E, but deploy behavior still depends on
vinext bundling.
> 
> **Overview**
> **Upgrades the Cloudflare web Worker stack to vinext 1.3.0 and
@vinext/cloudflare 1.2.0**, lifting the Dependabot pins that blocked
those versions after 1.3.0 caused production 502s from Worker memory/CPU
exhaustion.
> 
> The fix is an **app-level image facade** (`@/components/ui/image`):
Next builds keep a thin re-export of `next/image`, while the vinext
build aliases that module to `web-worker/image.tsx` instead of aliasing
`next/image` globally. That avoids vinext 1.3+ resolving its shim back
into the wrapper and infinite `<Image>` recursion. The worker wrapper
still builds srcsets and honors custom loaders because vinext does not
fully match Next’s `images.loaderFile` behavior.
> 
> **Call sites** (ads, navigation, media, public/editorial images) now
import the facade; ESLint **`no-restricted-imports`** enforces that in
`src/` and `web-worker/`. Playwright ESLint blocks move unchanged into
**`eslint.playwright.mjs`** so `eslint.config.mjs` stays under the line
limit.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
011830e. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Claude <noreply@anthropic.com>
The trailingSlash half of this PR is on main; next/image now applies
images.loaderFile inside the shared shim (image.tsx / image-props.ts)
instead of a separate entry, matching main's server-safe image split.
@AhmedElBanna80 AhmedElBanna80 changed the title fix(image): honor trailingSlash, fix custom-loader srcSet, support images.loaderFile fix(image): fix custom-loader srcSet, support images.loaderFile Oct 27, 2026
@AhmedElBanna80

Copy link
Copy Markdown
Contributor Author

Merged current main and trimmed this PR. The trailingSlash half is on main, so it is gone from the description. The conflicts came from the server-safe image split: next/image no longer goes through a separate image-external entry. The loader file is now applied in the shared shim (image.tsx for the component, image-props.ts for getImageProps), which also keeps it working from Server Components, and the RSC next/image entry and the user-alias handling on main are untouched. One behaviour change: next/legacy/image still ignores the loader file, but the module is now evaluated on legacy-only pages too. The static-export e2e passes (3/3) and goes red for the loaderFile case if the fallback is removed; vp check and the image unit files pass.

# Conflicts:
#	packages/vinext/src/index.ts
MrIago pushed a commit to MrIago/vinext that referenced this pull request Nov 14, 2026
…ages.loaderFile

Squashed from cloudflare#3686 (15 commits), rebased over the
blur placeholder and remote-image changes. The static-export e2e
fixture it adds is left out: it needs ipaddr.js as a fixture dependency,
which would change the lockfile.

Co-Authored-By: James <james@eli.cx>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AhmedElBanna80

Copy link
Copy Markdown
Contributor Author

@james-elicx Could you take a look when you have a moment? CI is green and the branch merges cleanly. This is one of five related PRs (#3686, #3741, #3759, #3768, #3771); I'm happy to rebase or split any of them if that makes reviewing easier. Thanks!

next/legacy/image again evaluated the images.loaderFile module on
legacy-only pages: image-props.ts imported the loader-file slot, and
legacy-image renders the shared component, which imports image-props.
Next.js's client/legacy/image.tsx never imports the aliased image-loader
module.

- shims/image-loader.ts (new, server-safe) owns the loader-file import,
  withConfiguredLoader and next/image's getImageProps.
- shims/image-base.tsx is the loader-agnostic component, moved from
  image.tsx. next/legacy/image renders it directly.
- shims/image.tsx stays the next/image entry (same alias target): it wraps
  image-base with withConfiguredLoader. The RSC next/image entry takes
  getImageProps from image-loader.
- image-props keeps buildImageProps (getImageProps without the loader file).

Test: importing next/legacy/image does not evaluate the loader-file slot,
and importing next/image does. It fails if legacy-image imports image.tsx.
@AhmedElBanna80

Copy link
Copy Markdown
Contributor Author

@james-elicx Pushed ad41a5fe8 to fix a regression from my 27 Oct merge of main. After that merge, next/legacy/image evaluated the images.loaderFile module on legacy-only pages again (the bonk finding from 7 Oct that d927ceb had fixed).

  • shims/image-loader.ts (new, server-safe) owns the loader-file import, withConfiguredLoader and next/image's getImageProps.
  • shims/image-base.tsx is the loader-agnostic component (moved from image.tsx). next/legacy/image renders it directly.
  • shims/image.tsx is still the next/image alias target and wraps image-base with the configured loader. The RSC next/image entry takes getImageProps from image-loader.

New unit test: importing next/legacy/image does not evaluate the loader-file slot, and importing next/image does. It fails if legacy-image imports image.tsx again. Results: vp check clean, check-shim-types clean, and image-component, image-loader-file, shims, image-optimization-parity and static-image-emission all pass (1594 tests). In vp pack output, only dist/shims/image-loader.js references the bare loader-file specifier. I also updated the two thread replies that pointed at image-external.tsx.

Could you run /bigbonk review on the new head when you get a chance?

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.

3 participants