Repository navigation
Description
Which project does this relate to?
Router
Describe the bug
Given a useLoaderData call like this inside a child route (/app/) it is sometimes possible for loaderData() to return undefined:
const loaderData = useLoaderData({
from: '/app',
});The requirements for this to happen seem to be quite specific. As far as I can tell, it seems that spa: { enabled: true }. I have also not been able to remove TanStack DB from the reproduction. In order for the issue to occur it seems that the loaderData() and the result of a live query must be used in the same expression. For example, this crashes (with Cannot read properties of undefined on the loaderData().length):
<pre>combined: {`${loaderData().length}:${rows().length}`}</pre>But this works without issue:
<pre>loaderData: {loaderData().length}</pre>
<pre>rows: {rows().length}</pre>It also seems like a live query must be used in both the parent and child routes. I'm actually not 100% sure if the issue is with router, start, db, or my code, but I was advised on discord to file it here.
Your Example Website or App
Steps to Reproduce the Bug or Issue
- Load up the stackblitz demo
- Click "Open /app"
- You should see the
TypeErrorfrom theloaderData().length - Click the 'Retry' button and it should render correctly.
You may need to attempt this several times (reloading the sandbox preview rather than the full sandbox). In my actual application I usually only run into this problem on hard reloads, and whilst shrinking it down for the reproduction it was a little intermittent suggesting possibly a race condition. This reproduction appears to throw the error for me consistently though.
Expected behavior
loaderData in this example is typed as Accessor<string>, and so I would expect it to never return undefined, and instead render the same was as when 'Retry' is clicked.
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.163.2
- DB Version: 0.2.9
- OS: macOS
- Browser: Chrome
- Browser Version: 145.0.7632.117
- Bundler: vite
- Bundler Version: 7.3.1
Additional context
No response
Activity
charlie-hadden commentedon Feb 28, 2026
I've continued to try and reproduce this without TanStack DB or TanStack Start, and I think I have finally gotten somewhere with that. Updated reproduction is here: https://stackblitz.com/edit/vitejs-vite-6k86ggta?file=src%2Froutes%2F%24slug%2Ftest.tsx
This one does trigger in a slightly different way. In this case, we use:
datais typed asstring, but it sometimes comes through asundefined. Because it presents in a slightly different way I'm not 100% sure it's the same issue. With my admittedly limited knowledge of Router's internals, I believe it is caused by the sameuseMatchbehaviour though.To reproduce the error you should be able to open the stack blitz, open the browser console, and click 'Navigate'. It seems like quite a reliable reproduction. For it to be reliable, the loader waits for longer than
pendingMs, and apendingComponentis set, though it does appear that thependingComponentat least is not a requirement.