Skip to content

fix: normalize static file cache paths on Windows#1578

Open
ikxin wants to merge 1 commit into
cloudflare:mainfrom
ikxin:main
Open

fix: normalize static file cache paths on Windows#1578
ikxin wants to merge 1 commit into
cloudflare:mainfrom
ikxin:main

Conversation

@ikxin
Copy link
Copy Markdown

@ikxin ikxin commented May 23, 2026

Summary

Fixes static asset serving in vinext start on Windows by normalizing StaticFileCache lookup keys to URL-style forward slashes.

On Windows, path.relative(base, file) returns paths with \ separators. StaticFileCache currently stores those paths directly as lookup keys, producing entries such as:

/_next\static\index-C5wrhk-x.css
/images\logo.svg

Browsers request URL paths with / separators:

/_next/static/index-C5wrhk-x.css
/images/logo.svg

Because the cache key and request pathname do not match, valid files that exist under dist/client are returned as 404 by vinext start.

This patch converts scanned relative file paths to URL path separators before inserting them into the static cache.

Reproduction

On Windows:

  1. Build an App Router project with static assets:
pnpm run build
pnpm exec vinext start
  1. Open a built route in the browser.
  2. Observe 404s for valid assets such as:
/_next/static/*.js
/_next/static/*.css
/images/logo.svg

The 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:

path.relative(base, file).replaceAll(path.sep, "/")

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 build succeeds.
  • vinext start serves the app route successfully.
  • Actual HTML-referenced assets under /_next/static/* return 200.
  • Public assets such as /images/logo.svg return 200.
  • Browser console no longer reports static asset 404s.

Related

Related to #1337 in that both involve _next/static 404 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.

Copilot AI review requested due to automatic review settings May 23, 2026 03:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

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.

2 participants