Skip to content

[vite-plugin v1 backport] Support local image URL transformations - #17315

Merged
NuroDev merged 5 commits into
codex/vite-v1-runtime-20261129from
codex/vite-v1-image-transforms-16678
Dec 3, 2026
Merged

NuroDev merged 5 commits into
codex/vite-v1-runtime-20261129from
codex/vite-v1-image-transforms-16678

Conversation

@petebacondarwin

@petebacondarwin petebacondarwin commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Backports the remaining Vite integration and regression coverage from #16678. With images.url_transformations enabled, /cdn-cgi/image/ transforms work locally, including Vite public/ files. Disabled transformations return 404 and disallowed origins return 403, as upstream specifies.

Depends on #17293, which already supplies the original Miniflare 5.20261129.0-beta runtime and coupled Wrangler 4.170.0 / workers-utils 0.60.0 graph from #17276. This PR adds no dependency upgrades or absent public source. The upstream runtime implementation and its tests remain in Miniflare. Wrangler's published getMiniflareWorkerOptions already supplies the per-worker image and route-hostname options.

Necessary v1 adaptations: v1 uses V4WorkerOptions and Wrangler snake_case config, so the router receives the equivalent imageUrlTransformations object (enabled / allowedOrigins). The upstream unsafeImageUrlTransformationsFetchViaPublicUrl option is copied directly. The original playground test and PNG are copied unchanged; cloudflare.config.ts is represented by v1's wrangler.jsonc with the equivalent name/date/assets/images fields. No alternate transform implementation is introduced. Wrangler, direct Miniflare and Vitest consumers receive their integration from upstream; this diff completes Vite v1.

Validation: the original playground regression fails before this integration (404 instead of 200) on the already-upgraded runtime and passes afterward in both dev and build/preview (2 tests each). Node 22.22.1 / pnpm 10.33.0: build passes, all 58 check tasks pass, all 8 retained package-test tasks pass including 287 plugin tests. OS and supported Vite matrix CI will validate the published PR head. A plugin minor changeset describes the new capability and intentional local routing behavior change.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: upstream docs follow general availability; the changeset explains local behavior and limitations.

Note

This is a contribution from an AI agent: Codex.


Devin Review

@changeset-bot

changeset-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6ecb639

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/vite-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@petebacondarwin

Copy link
Copy Markdown
Contributor Author

@mglewis @petebacondarwin — please check this v1 backport of #16678 and approve if it looks good. petebacondarwin is the verified latest human ant-core approver before merge.

#17293 already supplies the original public Miniflare/Wrangler runtime. This remaining integration maps v1 Wrangler fields into the same router image options and copies the public-URL setting, original playground regression and PNG. Published Wrangler already supplies the per-worker route-hostname fields. The original test fails 404 before this change and passes in dev and preview after it; build, full checks and retained package tests pass. The PR description explains the V4WorkerOptions and wrangler.jsonc adaptations.

@workers-devprod
workers-devprod requested review from a team and dario-piotrowicz and removed request for a team December 1, 2026 14:04
@workers-devprod

workers-devprod commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler

@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
npm i https://pkg.pr.new/@cloudflare/vite-plugin@17315

commit: 6ecb639

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — This backport passes the images.url_transformations config, the route hostname (routes takes precedence over an inherited route) and the public URL to the router worker, with regression tests for worker, assets-only and middleware modes. The only change since the last review is the Windows temp-path fix in the spec, and no issues were found.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

🚀 Release: ✅ LGTM

Release risk: low.

The change adds local /cdn-cgi/image/ transformation support. A minor plugin changeset is the right classification for a new capability. Deployed production behaviour is unchanged.


🔒 Security: ✅ LGTM

No issues found.

  • enabled and allowed_origins reach the router unchanged, so the origin allowlist still applies.
  • In middleware mode, the public URL comes from the socket address, not from request headers.

📖 AGENTS.md: ✅ LGTM

No issues found.


📋 Code Quality: ✅ LGTM

  • src/miniflare-options.ts:
    • The route hostname is taken from routes[0] when routes is set and from route otherwise. This matches Wrangler's routes ?? route precedence.
    • An empty routes: [] leaves the hostname unset.
    • A config with no images leaves imageUrlTransformations as undefined, so existing behaviour does not change.
  • src/plugins/dev.ts:
    • In middleware mode, publicUrl is set from the connection's socket once Miniflare is ready.
    • Every other mode still sets it from the listening handler.
  • Tests:
    • The spec covers a single route, the first of several routes, an environment's routes over an inherited route, no route, a disallowed origin (403), and middleware mode with forged Host and X-Forwarded-* headers.
    • The new Windows realpath temp-directory setup follows the existing pattern in runtime-bindings.spec.ts.

📝 Documentation: ✅ LGTM

No issues found. The changeset describes the new local behaviour for plugin users.


Reviewed commit: 6ecb639f

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@petebacondarwin
petebacondarwin force-pushed the codex/vite-v1-image-transforms-16678 branch from 4fa533d to 3710536 Compare December 3, 2026 15:06
…ute hostname

Match Wrangler's `routes ?? route` precedence so a named environment's
`routes` decides the hostname used to check same-host image sources
against `allowed_origins`, even when a top-level `route` is inherited.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@NuroDev

NuroDev commented Dec 3, 2026

Copy link
Copy Markdown
Member

clanky review

…m spec

Vite cannot load the Worker entry from the 8.3 short temp path on
Windows runners, so every worker-mode case failed. Use the same
realpath setup as `runtime-bindings.spec.ts`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codeowners reviews satisfied

@NuroDev
NuroDev merged commit 05a8bed into vite-plugin-v1 Dec 3, 2026
25 checks passed
@NuroDev
NuroDev deleted the codex/vite-v1-image-transforms-16678 branch December 3, 2026 16:58
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.

4 participants