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
https://stackblitz.com/edit/vitejs-vite-ruvpbctt?file=src%2Froutes%2Fapp%2Findex.tsx
Steps to Reproduce the Bug or Issue
- Load up the stackblitz demo
- Click "Open /app"
- You should see the
TypeError from the loaderData().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
Which project does this relate to?
Router
Describe the bug
Given a
useLoaderDatacall like this inside a child route (/app/) it is sometimes possible forloaderData()to returnundefined: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 theloaderData()and the result of a live query must be used in the same expression. For example, this crashes (withCannot read properties of undefinedon theloaderData().length):But this works without issue:
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
https://stackblitz.com/edit/vitejs-vite-ruvpbctt?file=src%2Froutes%2Fapp%2Findex.tsx
Steps to Reproduce the Bug or Issue
TypeErrorfrom theloaderData().lengthYou 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
loaderDatain this example is typed asAccessor<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
Additional context
No response