Skip to content

fix(solid-router): keep route-scoped accessors readable after navigation teardown#7607

Open
brenelz wants to merge 1 commit into
TanStack:solid-router-v2-prefrom
brenelz:fix/solid-router-route-scoped-accessor-teardown
Open

fix(solid-router): keep route-scoped accessors readable after navigation teardown#7607
brenelz wants to merge 1 commit into
TanStack:solid-router-v2-prefrom
brenelz:fix/solid-router-route-scoped-accessor-teardown

Conversation

@brenelz

@brenelz brenelz commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #7331
Closes #7330 (includes its failing test)

Problem

In Solid Router v2, route-scoped accessors such as Route.useParams() and Route.useSearch() are backed by a lazy createMemo in useMatch. If async work created by a route component (e.g. inside a createEffect or a pending promise) reads the accessor after navigating away, the memo re-executes against the current store state. The match is no longer in router.stores.matches and the navigation has finished (no pending match, not transitioning), so the read threw:

Invariant failed: Could not find an active match from "/posts/$postId"

Fix

useMatch now registers an onCleanup on the owning reactive scope. Once that scope is disposed (the route was unmounted), reads of the accessor return the last known value instead of throwing.

This is intentionally scoped to teardown: a still-mounted component that reads a genuinely missing match still throws, preserving the documented shouldThrow semantics and existing tests. Since useParams, useSearch, useLoaderData, and useRouteContext all route through useMatch, the fix covers all route-scoped accessors.

Testing

🤖 Generated with Claude Code

…ion teardown

Route-scoped accessors like Route.useParams() are backed by a lazy memo
in useMatch. When async work created by a route component read the
accessor after navigating away, the memo re-executed against the new
matches and threw "Invariant failed: Could not find an active match".

Track disposal of the owning reactive scope via onCleanup and return
the last known value for reads that happen after teardown, while still
throwing for mounted components that read a genuinely missing match.

Fixes TanStack#7331
Closes TanStack#7330

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a6133ef6-8d73-4839-b623-66a7f53d053f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit db4b860

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 6m 5s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2m 21s View ↗

☁️ Nx Cloud last updated this comment at 2026-06-11 23:51:23 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@7607

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7607

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7607

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@7607

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7607

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@7607

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@7607

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7607

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@7607

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@7607

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@7607

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@7607

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@7607

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@7607

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@7607

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@7607

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@7607

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@7607

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7607

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@7607

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7607

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@7607

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7607

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7607

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@7607

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@7607

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@7607

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@7607

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7607

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@7607

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@7607

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7607

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@7607

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@7607

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7607

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@7607

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7607

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7607

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@7607

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@7607

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@7607

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@7607

commit: db4b860

@codspeed-hq

codspeed-hq Bot commented Jun 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 2 untouched benchmarks
⏩ 1 skipped benchmark1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
ssr request loop (vue) 420.3 ms 484.6 ms -13.27%
client-side navigation loop (solid) 72.6 ms 66.2 ms +9.75%
ssr request loop (solid) 174.6 ms 162.5 ms +7.46%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing brenelz:fix/solid-router-route-scoped-accessor-teardown (db4b860) with solid-router-v2-pre (67a9040)2

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

  2. No successful run was found on solid-router-v2-pre (65133ed) during the generation of this report, so 67a9040 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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