Skip to content

fix: don't record a trailing slash for a prerendered root page combined with a base path#16472

Open
Bishwas-py wants to merge 3 commits into
sveltejs:mainfrom
Bishwas-py:fix-prerendered-root-trailing-slash
Open

fix: don't record a trailing slash for a prerendered root page combined with a base path#16472
Bishwas-py wants to merge 3 commits into
sveltejs:mainfrom
Bishwas-py:fix-prerendered-root-trailing-slash

Conversation

@Bishwas-py

@Bishwas-py Bishwas-py commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

closes #13310

The root route's own path is empty, so when combined with a base path it gets recorded as base + '/' in prerendered.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 from prerendered.paths (e.g. adapter-netlify's excludedPath) end up excluding the wrong URL form, so one of /base-path or /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 + '/', so trailingSlash: 'always' routes elsewhere are untouched (verified against the existing basics prerendering fixture, which already asserts a trailingSlash: 'always' route keeps its slash).

Verified end-to-end on real Netlify, not just locally: packed a patched @sveltejs/kit tarball, built two standalone repro apps (root page prerendered + base path set, deployed with adapter-netlify), one against unpatched @sveltejs/kit, one against this fix, deployed both:

Also includes two unrelated chore commits fixing the lint-all failures that exist on main since #16378. #16438 fixes the same two breakages independently (inlining the import instead of export {} 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:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

…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.
@pkg-svelte-dev

pkg-svelte-dev Bot commented Jul 22, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from eef150d:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/eef150d3081df2db483e7ed44d48a0242e3f5c90

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16472

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eef150d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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.
@Bishwas-py

Copy link
Copy Markdown
Contributor Author

added da59deb regenerating types, unrelated to the fix. running pnpm prepublishOnly against a clean, unmodified main checkout produces this same whitespace-only diff (verified in a separate worktree), so it's pre-existing drift, not something this PR introduced. committing it because the lint-all CI check requires it to pass regardless of cause.

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.

@Nic-Polumeyv Nic-Polumeyv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread packages/kit/src/exports/env/index.js
@Bishwas-py
Bishwas-py requested a review from Nic-Polumeyv July 22, 2026 14:50
Nic-Polumeyv
Nic-Polumeyv approved these changes Jul 22, 2026
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