fix: don't record a trailing slash for a prerendered root page combined with a base path#16472
fix: don't record a trailing slash for a prerendered root page combined with a base path#16472Bishwas-py wants to merge 3 commits into
Conversation
…ed with a base path Closes sveltejs#13310. The root route's own path is empty, so combined with a base path it's recorded as base + '/' in prerendered.paths, a trailing slash the type has always promised these paths don't have. Adapters that build an exclusion list from prerendered.paths (e.g. adapter-netlify's excludedPath) end up excluding the wrong URL form, so one of /base-path or /base-path/ silently breaks depending on the adapter's own trailing-slash handling. Strips the slash only when the recorded path is exactly base + '/', so trailingSlash: 'always' routes elsewhere are untouched.
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/eef150d3081df2db483e7ed44d48a0242e3f5c90Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
🦋 Changeset detectedLatest commit: eef150d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Pre-existing drift on main, unrelated to the trailing-slash fix: running pnpm prepublishOnly against a clean, unmodified main checkout produces this same whitespace-only diff. Committing it because the CI lint-all check requires generated types to match a fresh regeneration, and this is blocking regardless of cause.
|
added da59deb regenerating types, unrelated to the fix. running |
tsc reports EnvVarConfig as unused when it's only referenced inside a @template bound and the file has no other module-level export statement (reproduced the same failure on hooks/index.js by temporarily removing its export { sequence } line, confirming the trigger). An empty export {} statement is enough to fix it.
There was a problem hiding this comment.
Reviewed this since it overlaps with #16438. The fix looks right to me, and both Netlify deployments behave as described.
One thing not visible in the diff: on adapter-cloudflare the worker's trailing-slash redirect for the root flips direction, /base-path/ now 308s to /base-path instead of the other way around. That matches the default trailingSlash: 'never' canonical form so it seems correct, just flagging it since Cloudflare isn't covered by the added test.
closes #13310
The root route's own path is empty, so when combined with a base path it gets recorded as
base + '/'inprerendered.paths, a trailing slash the type has always documented these paths as not having (private.d.ts: "An array of prerendered paths (without trailing slashes...)"). Adapters that build a static-file exclusion list fromprerendered.paths(e.g.adapter-netlify'sexcludedPath) end up excluding the wrong URL form, so one of/base-pathor/base-path/breaks depending on how the adapter/host then handles the mismatch.This strips the trailing slash only when the recorded path is exactly
base + '/', sotrailingSlash: 'always'routes elsewhere are untouched (verified against the existingbasicsprerendering fixture, which already asserts atrailingSlash: 'always'route keeps its slash).Verified end-to-end on real Netlify, not just locally: packed a patched
@sveltejs/kittarball, built two standalone repro apps (root page prerendered + base path set, deployed withadapter-netlify), one against unpatched@sveltejs/kit, one against this fix, deployed both:/base-path(no trailing slash) does not.Also includes two unrelated
chorecommits fixing thelint-allfailures that exist onmainsince #16378. #16438 fixes the same two breakages independently (inlining the import instead ofexport {}for the TS6133 one). Whichever of these two PRs merges first, the other will need a rebase.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits