fix: correctly serve ISR pages with trailing slash set to 'always' - #16903
Conversation
Adds a route with ISR enabled and trailingSlash set to "always" along with a platform test that navigates to it and verifies the URL pathname stays correct, the page renders, and no network or console errors occur. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/8ab1c3eafee04b2d06867377a7805e828e4754e0Open in |
|
…vent redirect loops When ISR is enabled on a page with trailingSlash: 'always', the __pathname query param didn't include the trailing slash, causing SvelteKit to issue a redirect. Since ISR rewrites route back through the same handler, this created an infinite loop (visible as doubled path segments in the URL). Fix: detect when the Vercel route pattern has a trailing /? optional slash, convert it to a capture group (/)?, and use the corresponding backreference in __pathname so the slash is preserved when present. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…isr-trailing-slash-test
dc0723d to
85770ef
Compare
Co-authored-by: Nic Polumeyv <nicolas.polum@outlook.com>
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
|
@Nic-Polumeyv can you explain how the fix works? What happens to ISR routes with dynamic segments? Are they disallowed now or do they just still work? |
|
No problem, took me a couple hours to figure out! Vercel resolves a request in three steps (first match wins): adapter-vercel put every ISR src route in step 3. Only a src route attaches
The The fix puts ISR routes with no dynamic segments in step 1. Dynamic ones stay in step 3, since a Separately, Dynamic ISR routes still work, nothing about their placement changed. The one difference is |
Fixed #12556
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