Skip to content

[wrangler] Preserve inferred zone in Miniflare worker options#13792

Open
mihaip wants to merge 1 commit intocloudflare:mainfrom
mihaip:codex/vite-dev-miniflare-zone
Open

[wrangler] Preserve inferred zone in Miniflare worker options#13792
mihaip wants to merge 1 commit intocloudflare:mainfrom
mihaip:codex/vite-dev-miniflare-zone

Conversation

@mihaip
Copy link
Copy Markdown

@mihaip mihaip commented May 2, 2026

Fixes #13791.

Summary

@cloudflare/vite-plugin uses unstable_getMiniflareWorkerOptions() to build the local Miniflare worker config. That helper was not forwarding the local dev zone, so Miniflare fell back to <worker>.example.com for the CF-Worker header.

This makes the helper reuse Wrangler's existing host inference logic and pass the resulting zone through in workerOptions, so the Vite local-dev path matches the existing wrangler dev --local path.

That existing path already:

This change mirrors that behavior for callers of unstable_getMiniflareWorkerOptions().

Tests

  • add regression coverage for dev.host
  • add regression coverage for route-based host inference

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 2, 2026

🦋 Changeset detected

Latest commit: bdab3d9

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

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

@mihaip mihaip marked this pull request as ready for review May 2, 2026 18:34
@mihaip mihaip requested a review from workers-devprod as a code owner May 2, 2026 18:34
@workers-devprod workers-devprod requested review from a team and ascorbic and removed request for a team May 2, 2026 18:35
@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fix-vite-dev-miniflare-zone.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/unstable-get-miniflare-worker-options.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/integrations/platform/index.ts: [@cloudflare/wrangler]

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines +27 to +36
dev: {
ip: "localhost",
port: undefined,
local_protocol: "http",
upstream_protocol: "http",
enable_containers: false,
...overrides.dev,
},
...overrides,
} as unknown as Config;
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.

🟡 makeConfig spread ordering causes dev defaults to be silently overwritten

In the makeConfig helper, when overrides.dev is provided, the dev defaults (ip, port, local_protocol, upstream_protocol, enable_containers) are first correctly merged via ...overrides.dev inside the dev object (line 33), but then immediately overwritten by ...overrides at the top level (line 35). Because overrides contains the key dev: { host: "example.workers.dev" }, the top-level spread replaces the entire merged dev with just { host: "example.workers.dev" }, discarding all defaults.

The first test passes only by coincidence—getMiniflareZone only reads config.dev.host and returns early. But any future test that supplies overrides.dev and relies on the default dev properties (e.g., enable_containers) further down in unstable_getMiniflareWorkerOptions (packages/wrangler/src/api/integrations/platform/index.ts:522) will silently get undefined values instead of the intended defaults.

Suggested change
dev: {
ip: "localhost",
port: undefined,
local_protocol: "http",
upstream_protocol: "http",
enable_containers: false,
...overrides.dev,
},
...overrides,
} as unknown as Config;
dev: {
ip: "localhost",
port: undefined,
local_protocol: "http",
upstream_protocol: "http",
enable_containers: false,
...overrides.dev,
},
...overrides,
dev: {
ip: "localhost",
port: undefined,
local_protocol: "http",
upstream_protocol: "http",
enable_containers: false,
...overrides.dev,
},
} as unknown as Config;
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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.

Can you add a test (and probably some handling in the code) for the case where the host cannot be inferred? e.g. routes: "*/*".

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 7, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk May 7, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 7, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13792

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13792

miniflare

npm i https://pkg.pr.new/miniflare@13792

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13792

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13792

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13792

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13792

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13792

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@13792

wrangler

npm i https://pkg.pr.new/wrangler@13792

commit: bdab3d9

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

vite dev drops zone before Miniflare, causing CF-Worker to fall back to <worker>.example.com

3 participants