Root-absolute asset URLs, so the 404 page keeps its styles at any depth - #228
Merged
Merged
Conversation
SvelteKit 2 defaults kit.paths.relative to true, so every prerendered page linked its build artifacts relative to itself: ./_app/... at the top level, ../../_app/... two levels down. Cloudflare Pages answers a missing URL at any depth with 404.html, and on /some/deep/missing-page that ./_app/... resolved to /some/deep/_app/..., itself a 404 served as text/html: the not-found page rendered without its CSS, its modules never loaded and the client never started. Its favicons and manifest (%sveltekit.assets% in app.html) failed the same way. With relative: false both are written root-absolute (/_app/..., /favicons/...). The 1371 pages are otherwise unchanged: resolving every relative URL of the old build against the page's own URL gives the new HTML byte for byte, scripts included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Every prerendered page linked its build artifacts relative to itself, e.g.
./_app/immutable/assets/0.1TuYpimw.css, because SvelteKit 2 defaultskit.paths.relativetotrue. Cloudflare Pages answers a missing URL at any depth with404.html. On https://langx.io/some/deep/missing-page that./_app/…resolves to/some/deep/_app/…, which is itself a 404 served astext/html. So the not-found page rendered unstyled, its modules never loaded and the client never started. Its favicons and manifest (%sveltekit.assets%inapp.html) failed the same way. Pages at their own URLs were fine, because there the relative path lands at the root.kit.paths.relative: falsewrites those references root-absolute (/_app/…,/favicons/…). The site is only ever served from the domain root, pages.dev branch previews included, so the relative form was not needed. The top-levelconfig.paths = { base: … }further down is left alone. SvelteKit never reads it (pathsbelongs underkit), and moving it underkitwould apply CI'sBASE_PATH=/websiteto every URL.Checked, on Kit 2.70.3 under Node 20 (as in CI):
npm run check: 0 errors; the 2 warnings are the existingline-clampones.vite build: 1371 HTML files, the same as before.build/404.htmlandbuild/tools/say/hello.htmllink every stylesheet and module under/_app/. No page in the build has a relativehref,srcorimport()left.hrefs that became root-absolute: modulepreloads to/_app/and favicon/manifest links to/favicons/. Each still names the same path. A stricter check: resolve every relative URL in the old build against the page's own URL, including the bootstrap'sbaseand itsimport()s. That gives the new HTML byte for byte, scripts included, and the 237 artifacts referenced map one-to-one. Outside_app/every file is identical. Inside it, the fonturl()s in the CSS and Vite's preload lists became absolute too, with the same targets. Two chunks keep their names even though their preload lists changed, because Vite fills those lists in after hashing. The preload helper did not change and resolves both forms to the same URLs, so a cached copy of either is harmless.vite preview:/,/tools/say/helloand/some/deep/missing-pageload every stylesheet with no failed requests, and the client starts. However,vite previewrenders unknown URLs on the server instead of serving404.html, so it cannot show this bug. A small static server that answers the way Pages does (the file, else.html, else404.htmlwith status 404) can. On the old build,/some/deep/missing-pageapplied 0 of 6 stylesheets and all 25_apprequests failed. On the new build, all 6 applied, none failed, and "Back to the start" navigates client-side.🤖 Generated with Claude Code