Repository navigation
Closed
Labels
Milestone
Description
Which project does this relate to?
Start
Describe the bug
Redirecting in server functions or middleware causes a crash in certain situations, the most reliable is when you initially visit the application from a browser url.
For some reason router cannot find a match id for the route and assertion then kills the entire dev server:
| invariant( |
Full stack trace:
file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/tiny-invariant/dist/esm/tiny-invariant.js:12
throw new Error(value);
^
Error: Invariant failed: Could not find match for matchId "/". Please file an issue!
at invariant (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/tiny-invariant/dist/esm/tiny-invariant.js:12:11)
at Object.s (/home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/solid-router/src/Match.tsx:28:7)
at state (/home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/solid-router/src/useRouterState.tsx:32:35)
at eval (/home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/solid-store/src/index.tsx:30:22)
at file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/store/dist/esm/scheduler.js:35:19
at Set.forEach (<anonymous>)
at __notifyListeners (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/store/dist/esm/scheduler.js:34:19)
at __flush (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/store/dist/esm/scheduler.js:64:9)
at batch (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/store/dist/esm/scheduler.js:95:9)
at file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/router-core/dist/esm/router.js:629:19
at RouterCore.startViewTransition (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/router-core/dist/esm/router.js:740:9)
at Object.onReady (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/router-core/dist/esm/router.js:625:22)
at triggerOnReady (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/router-core/dist/esm/load-matches.js:10:27)
at loadMatches (file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/router-core/dist/esm/load-matches.js:568:26)
at async file:///home/sebba/work/builds/tanstack-start-solid-invariant-failed-reproduction/node_modules/@tanstack/router-core/dist/esm/router.js:617:13
Node.js v22.21.0
error: script "dev" exited with code 1
Your Example Website or App
Steps to Reproduce the Bug or Issue
Application has two routes / and /about
/ route has a server function that is called in the component and redirects you to /about
- Open the
/route in the browser - Your dev server should exit with status code 1 and show you
Error: Invariant failed: Could not find match for matchId "/". Please file an issue!error
Note:
If you go to /about route and click the link that takes you to / route, redirect will work fine and take you back to /about
Expected behavior
Expected behavior is that redirect works regardless of how link was accessed
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.133.27
- OS: Linux
- Browser: Chrome (helium), Firefox (zen)
- Browser Version: Version 0.5.8.1 (Official Build, Chromium 141.0.7390.122), 1.17.3b (Firefox 144.0)
- Bundler: vite
- Bundler Version: 7.1.12
Additional context
No response
Activity
[-]Start (solid): Redirecting inside server functions causes a crash - Invariant failed[/-][+]solid-start: Redirecting inside server functions causes a crash - Invariant failed[/+]birkskyum commentedon Oct 26, 2025
@s3bba , it should work if you set
ssr: 'data-only'like below here:Does it solve your issue?
s3bba commentedon Oct 26, 2025
@birkskyum Yes this solves the Invariant failed error, but using
data-onlymeans I'm opting out of component rendering on the server right? Ideally I would still like to server render my components with redirect working - or is this not supported?birkskyum commentedon Oct 26, 2025
Right now it only works with data-only for solid, but it's WIP to make it work with
ssr: trueas well. There's a ticket heressr: true#5639birkskyum commentedon Oct 26, 2025
related to
ssr: true#5639birkskyum commentedon Oct 28, 2025
@s3bba , you can set
ssr: trueif you do this in the query clients3bba commentedon Oct 28, 2025
@birkskyum Cannot confirm this, the invariant failed error still happens with this option for me.
I was already using this in my project, I did double check on the reproduction example and it also does not make a difference there.
birkskyum commentedon Oct 28, 2025
@s3bba , I've added a test for your case in #5668 , and we'll see to getting it working. So far i can see the redicect in the server function works if it's called from a loader. I'll try to see if we can make the solid-query work as well.
birkskyum commentedon Nov 3, 2025
@s3bba , we've just now merged a fix that should be resolving this issue, included automated testing. Would you be able to try this with the latest version of all the tanstack solid packages (query, query-ssr, router, start (1.134.10) etc.)?
s3bba commentedon Nov 3, 2025
@birkskyum Yes, I can confirm, invariant error has been fixed on the reproduction example and in my project with SSR enabled. Thanks for the quick fix!