Skip to content

fix: don't cache preloaded redirect results#16486

Open
ondraulehla wants to merge 1 commit into
sveltejs:mainfrom
ondraulehla:fix/preload-redirect-cache
Open

fix: don't cache preloaded redirect results#16486
ondraulehla wants to merge 1 commit into
sveltejs:mainfrom
ondraulehla:fix/preload-redirect-cache

Conversation

@ondraulehla

Copy link
Copy Markdown

closes #16484

When a link is preloaded and the target's load returns redirect(...),
the client caches that redirect result and replays it on navigation
without re-running load. The cache is only cleared once a navigation
commits, and a redirect never commits one. So a preloaded redirect into
a pair of mutually redirecting routes loops until the 20 redirect limit,
even when a fresh evaluation would resolve. The issue has a minimal
repro of an onboarding style gate.

I made _preload_data discard the cache when the result is a redirect.
This matches how it already refuses to cache errors, since both are
transient results that have to be re-evaluated at navigation time.

The new test reproduces the gate scenario from the issue. It preloads a
route whose load redirects, then clicks. Without the fix it ends in a
redirect loop, with the fix the navigation resolves. Passes in dev and
build modes.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

  • Relevant suites pass (data-sveltekit and redirect blocks, dev and build). lint-all currently fails on upstream main itself (pre-existing, unrelated)

Changesets

  • Changeset included (@sveltejs/kit patch, fix: prefix)

Edits

  • 'Allow edits from maintainers' is checked

The preload cache stored redirect results from load and replayed them on
navigation without re-running load. Since the cache is only cleared once
a navigation commits and a redirect never commits one, a preloaded
redirect into a mutually-redirecting pair looped until the 20-redirect
limit, even when a fresh evaluation would resolve.

Discard the cache when the preload resolves to a redirect, matching the
existing behavior for errors: both are transient results that must be
re-evaluated at navigation time.

Fixes sveltejs#16484
@pkg-svelte-dev

Copy link
Copy Markdown

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

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

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

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 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: df6f5f3

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

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.

1 participant