Skip to content

fix: reset preload flags when a route preload throws - #716

Merged
ryansolid merged 1 commit into
solidjs:nextfrom
brenelz:fix/preload-throw-intent
Nov 3, 2026
Merged

ryansolid merged 1 commit into
solidjs:nextfrom
brenelz:fix/preload-throw-intent

Conversation

@brenelz

@brenelz brenelz commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

If a route preload throws, every later query read in the session is treated as a preload. Query redirects and thrown Responses are then ignored. A redirect thrown by a guard query reaches the nearest Errored boundary as a raw Response instead of navigating. One hover over a link whose route preload has a bug is enough to cause this.

Root cause

preloadRoute sets the module-level preloadIntent to "preload" and inPreloadFn to true, runs each matched level's preload, then resets both after the loop. The reset is not in a finally, so a throw from route.preload() or component.preload() skips it. query reads preloadIntent on every call and skips settle() and handleResponse while it is set. createRouteContext has the same pattern for inPreloadFn.

Changes

  • preloadRoute restores both flags in a finally.
  • createRouteContext restores inPreloadFn in a finally. The root-level preload in routers/components.tsx already did this.
  • Both now restore the previous value instead of false, so a preload started from inside another preload does not clear the outer one's flag.
  • A throwing preload still throws as before.

Verification

test/preload-throw.spec.tsx covers a throw from usePreloadRoute followed by a redirecting query, a nested preload, and a throw from a route preload during navigation. Both tests fail on next and pass with this change.

  • npx vitest run: 730 passed
  • npx vitest run --config vitest.config.server.ts: 105 passed
  • npm run test:types and npm run build: pass

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 10452bd

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

This PR includes changesets to release 1 package
Name Type
@solidjs/router 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

@ryansolid
ryansolid merged commit 1a91dfa into solidjs:next Nov 3, 2026
4 checks passed
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