fix: normalize static file cache paths on Windows#1578
Open
ikxin wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes static asset serving on Windows in vinext start by ensuring StaticFileCache uses URL-style (/) path separators for its lookup keys, matching browser request pathnames.
Changes:
- Normalize
path.relative(base, file)results to forward-slash URL paths before inserting into the static file cache.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Fixes static asset serving in
vinext starton Windows by normalizingStaticFileCachelookup keys to URL-style forward slashes.On Windows,
path.relative(base, file)returns paths with\separators.StaticFileCachecurrently stores those paths directly as lookup keys, producing entries such as:Browsers request URL paths with
/separators:Because the cache key and request pathname do not match, valid files that exist under
dist/clientare returned as404byvinext start.This patch converts scanned relative file paths to URL path separators before inserting them into the static cache.
Reproduction
On Windows:
pnpm run build pnpm exec vinext startThe files exist on disk under
dist/client, but the production server cannot serve them because the in-memory static cache uses backslash-separated keys.Fix
Normalize the relative path generated during static file scanning:
This keeps behavior unchanged on POSIX platforms and makes Windows cache keys match URL pathnames.
Verification
Verified in a Windows project using
vinext@0.0.52:pnpm run buildsucceeds.vinext startserves the app route successfully./_next/static/*return200./images/logo.svgreturn200.Related
Related to #1337 in that both involve
_next/static404 handling, but this PR fixes a different root cause: valid static assets on Windows are cached under backslash-separated keys.Similar class of Windows path normalization issue as #825.