Skip to content

fix: normalize windows backslash in css url path#825

Merged
james-elicx merged 1 commit intomainfrom
james/normalize-css-url-path
Apr 12, 2026
Merged

fix: normalize windows backslash in css url path#825
james-elicx merged 1 commit intomainfrom
james/normalize-css-url-path

Conversation

@james-elicx
Copy link
Copy Markdown
Collaborator

No description provided.

@james-elicx
Copy link
Copy Markdown
Collaborator Author

/bigbonk review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 12, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@825

commit: b8ca018

@github-actions
Copy link
Copy Markdown

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk bot left a comment

Choose a reason for hiding this comment

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

Correct fix. On Windows, path.join() produces backslash separators (C:\Users\...\fonts\geist-abc.woff2), which then get written verbatim into the cached CSS url() values. The downstream _rewriteCachedFontCssToServedUrls() does a split(cacheDir).join(servedPrefix) — but since cacheDir is also built with path.join, it uses backslashes too, so the split/join works and the cache-dir prefix gets replaced. The problem is the remaining path segments after the prefix still have backslashes (e.g. url(/assets/_vinext_fonts\geist-abc\geist-def.woff2)), producing broken CSS URLs in production.

The .replaceAll("\\", "/") normalizes the filesystem path to forward slashes before it's written into the CSS cache, which is the right place to do it — at the boundary where a filesystem path becomes a URL path. This is consistent with the pattern used across the rest of the codebase (request-pipeline.ts, prod-server.ts, app-router-entry.ts, image-optimization.ts, etc.).

One thing worth noting: the writeBundle hook at line 968 uses path.relative(cacheDir, src) to compute the relative path for the copy destination. On Windows this would also produce backslash separators, but since that result feeds into path.join(targetRoot, relative) which is used purely as a filesystem path (not a URL), it's fine — fs.mkdirSync and fs.copyFileSync handle native separators correctly.

LGTM.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 12, 2026

Reviewed and approved PR #825. The fix is correct — on Windows, path.join() produces backslash separators that were being written into the cached CSS url() values without normalization. The .replaceAll("\\", "/") converts the filesystem path to a proper URL path at the right boundary (where filesystem paths become CSS URL references), consistent with the same pattern used across a dozen other places in the codebase.

github run

@james-elicx james-elicx enabled auto-merge (squash) April 12, 2026 10:13
@james-elicx james-elicx merged commit cf1f33b into main Apr 12, 2026
32 checks passed
@james-elicx james-elicx deleted the james/normalize-css-url-path branch April 12, 2026 10:14
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.

1 participant