fix: normalize windows backslash in css url path#825
Conversation
|
/bigbonk review |
commit: |
|
There was a problem hiding this comment.
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.
|
Reviewed and approved PR #825. The fix is correct — on Windows, |
No description provided.