Repository navigation
fix(vite): do not crash serving public assets from the dev worker - #5121
Conversation
The node public assets reader resolved paths against `__nitro_main__`, which the Vite dev runner does not set. Dev manifest paths are already absolute.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
commit: |
With
nitro/vitein dev, the dev worker's static handler returns a500for public assets in two cases:public/is deleted while the dev server runs, and its URL is requested againserverFetch()(internal fetch), even one that existsRoot cause
The
nodepublic assets reader (#nitro/virtual/public-assets-node) resolves each manifest path againstglobalThis.__nitro_main__. The rollup, rolldown and rspack builds set that global in the entry chunk, but the Vite dev runner does not, sofileURLToPath(undefined)throws.In dev, the manifest paths are already absolute (
resolve(asset.dir, file)), so__nitro_main__is not needed there.Fix
The reader template uses the manifest path as is in dev. The production output does the same thing as before, so built servers are unchanged.
After the fix, Vite matches the other builders: a deleted file gets an uncached
404, and internal fetch of an existing asset works.Not changed here: in dev, the worker's manifest is only rendered at build time. So a deleted file still gets a
404from the static handler instead of falling through to a route on the same path, until the next rebuild. This is the same on all builders on main, and has a different cause.Related to #5120 (same
500when a wholepublic/dir is removed).Tests
New tests in the dev reload suite, for Vite (
test/vite/scan-reload.test.ts) and the builders (test/unit/dev-scan-reload.test.ts): a public asset that exists at startup is fetched directly and throughserverFetch(), then deleted.[ 'asset', 500 ], and[ 500, 500 ]after the delete) and passes with the fix, 5 runs each.test/vite+test/unit(rolldown),test/presets/nitro-devandtest/presets/nodepass, also after a fullpnpm build.🤖 Generated with AI assistant