fix: re-evaluate preloaded redirects before navigation - #16930
Closed
bmdavis419 wants to merge 1 commit into
Closed
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/a089be9b1acd62b531c1e86949ce709328ca481eOpen 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: a089be9 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 |
teemingc
reviewed
Aug 25, 2026
Comment on lines
+1419
to
+1423
| const result = await cache.promise; | ||
| if (result.type !== 'redirect') return result; | ||
|
|
||
| // Redirects depend on transient state and must be reevaluated when navigating. | ||
| if (load_cache === cache) discard_load_cache(); |
Member
There was a problem hiding this comment.
I don't think this is the right fix. See #16484 (comment)
teemingc
requested changes
Aug 25, 2026
Rich-Harris
pushed a commit
that referenced
this pull request
Aug 27, 2026
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>
Member
|
closing in favour of #16955 |
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.
Prevent stale preloaded redirects from causing incorrect navigation and redirect loops.
Important files:
packages/kit/src/runtime/client/client.jspackages/kit/test/apps/basics/test/cross-platform/client.test.jspackages/kit/test/apps/basics/src/routes/routing/preloading/redirect/[step]/+page.server.jsBefore and after:
References #16484.
Summary by CodeRabbit
Bug Fixes
Tests