Repository navigation
fix(router): buildEnv "auto" reads the wrangler config of the Vite root - #1045
Merged
Merged
Conversation
commit: |
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1037.
Problem
With
rango({ preset: "cloudflare", buildEnv: "auto" }), building from a directory other than the app's (vite build tests/cloudflare-basicfrom the repo root) gave build-timePrerender/Statichandlers anenvwithout the app's bindings. The/build-envprerender failed withCannot read properties of undefined (reading 'put'); building from inside the app passed.getPlatformProxy()was called with no options, so wrangler searched for its config fromprocess.cwd(), and also resolved its default persist path againstprocess.cwd().Before / after
Consumer side: nothing to change. The same config now works from any working directory.
Semantics
wrangler.json,wrangler.jsonc,wrangler.toml, in that order) found in the Vite root or an ancestorgetPlatformProxy({ configPath, persist: { path: <Vite root>/.wrangler/state/v3 } })getPlatformProxy(), as before.wrangler/deploy/config.json)configPathis used. Unchanged for apps without a redirect, left as isWrangler facts (installed
wrangler-dist/cli.js):findWranglerConfigat line 3172 checkswrangler.json,wrangler.jsonc,wrangler.tomlwith a find-up from the reference path (defaultprocess.cwd()).getPlatformProxypassesoptions.configPathtoreadConfigat line 370330. Its persist root is the literal".wrangler/state/v3"(getMiniflarePersistRoot, line 370381) with no config-relative resolution, so it lands underprocess.cwd(); hencepersistis passed explicitly. It is anchored to the Vite root, not to the config's directory:@cloudflare/vite-pluginreads local state from<Vite root>/.wrangler/state/v3in dev and preview (getPersistenceRoot(root, persistState),dist/index.mjs:64251), so build-time writes land where dev and preview read them also when the config sits above the root. When the working directory is the root, the path is the one wrangler used before.Code change
packages/rangojs-router/src/vite/router-discovery.ts: newwranglerProxyOptions(root)(find-up with wrangler's names and order) and one changed call;resolveBuildEnvis now exported so the test can drive it. No public option; the Cloudflare Vite plugin's ownconfigPathis not read.Test plan
src/vite/__tests__/build-env-auto-root.test.ts(stubwranglerpackage recording the options, cwd changed away from the root): config under root is passed with the persist path under the root; name order; upward search from a nested root (state stays under the nested root); no config givesundefinedoptions. Red without the fix (3 of 4 fail:expected undefined to deeply equal { configPath, persist }), green with it.vite build tests/cloudflare-basicfrom the repo root now passes (OK /build-env).playwright test --project=production --no-deps build-envintests/cloudflare-basic: 2 passed.test:unit:all, lint, format,check:e2e-bucketing,check:e2e-parity --strict,check:docs-api.test:hmr-routes-local: 21 passed.build-envsuites cover the normal build.Notes
tests/cloudflare-basicstill logsSHELL SKIP ... Cannot read properties of null (reading 'useState')for its 5 PPR shells (runtime capture is kept, exit 0). The in-directory build captures them (SHELL OK). That is a separate working-directory dependence in the shell-capture server, hidden until now because this build failed earlier. Filed as Vite started from another working directory: plugin-rsc externalizes the app's React-peer dependencies, so build-time and dev PPR shell captures are skipped #1044, not addressed here..catch(() => {})in the upward-search test that would have hidden a failure is gone. Skipped: rewriting the find-up loop aswhile (true)(style), and testing the pure helper instead of the call (the test would no longer prove the options reachgetPlatformProxy).skills/cloudflare/SKILL.md,docs/internal/feature-map.md, and thetests/cloudflare-basicsentence indocs/design/per-app-cache-version.md.