Skip to content

fix: discard a consumed preloaded redirect before following it - #16955

Merged
Rich-Harris merged 1 commit into
version-3from
fix-preload-redirect-loop
Aug 27, 2026
Merged

fix: discard a consumed preloaded redirect before following it#16955
Rich-Harris merged 1 commit into
version-3from
fix-preload-redirect-loop

Conversation

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

In runtime/client/client.js, _preload_data stores every load_route result in load_cache and load_route hands the entry back whenever the intent id matches. navigate only clears load_cache on the commit path, after history.pushState; the redirect branch recurses into navigate for the redirect target and returns before that. So when a preloaded route redirects and a later hop of the same navigation comes back to it (a gate: /dashboard redirects to /select until a flag is set, /select sets it and redirects to /dashboard), the cached redirect is replayed without a fetch on every return until the 20-redirect limit renders the 500 page.

Discard the consumed entry in the redirect branch before recursing, keyed on intent.id so a preload of a different route (such as the redirect target) survives. The first hop is still served from the preload; anything after it loads fresh.

Fixes #16484.

Replaces #16930. Thank you for the attempt @bmdavis419, big fan of your content.

Co-authored-by: Benjamin Davis <davis.benjamin41902@gmail.com>
@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 6a9437d:

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

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

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6a9437d

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

@svelte-docs-bot

Copy link
Copy Markdown

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

sad that we can't induct @bmdavis419 as a contributor — next time! — but happy for the fix

@Rich-Harris
Rich-Harris merged commit a373fff into version-3 Aug 27, 2026
40 checks passed
@Rich-Harris
Rich-Harris deleted the fix-preload-redirect-loop branch August 27, 2026 20:42
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.

Preloaded redirect results are cached and replayed, causing stale redirects and redirect loops

2 participants