Closed Arilas closed 1 week ago
Yeah. I have the same issue
I've just run into the same issue. In my case it is also where I'm throwing a redirect in my beforeLoad
to redirect away from a bare route that has no search params to one which has a valid default param populated.
beforeLoad
seems to get called again immediately after the redirect with the newly updated deps
from loaderDeps
, but with an undefined
context
value.
If I instead use the deprecated navigate
arg in beforeLoad
(rather than throw redirect({...})
) everything works as expected, in case others are looking for a workaround.
Actually, I just upgraded my app from v1.35.6 to v1.39.4 and I can no longer reproduce this issue. Seems like it may have been fixed @Arilas, maybe try your repo on the latest version and see if it's still broken?
I take it back, I'm still encountering this issue. Not sure how I thought it was fixed last time.
For me, it happens in two case:
/
that renders a <Navigate />
redirect. The 2nd redirected route then has an undefined context
. I updated my code to throw redirect
instead of using <Navigate />
on my initial route, and that takes care of the issue./jobs/
throws a redirect in beforeLoad
to the same route, but with updated an search
value, the loader
gets called an initial time with no context
. This one gets worked around using the following and avoiding destructuring context as part of the loader function:
loader: async ({ context, deps: { limit, state } }) => {
if (!context) {
// workaround for this issue:
// https://github.com/TanStack/router/issues/1751
return;
}
// ...
Although I didn't put together a simple reproduction, my workaround changes are visible in https://github.com/riverqueue/riverui/pull/80
this will be fixed by #1907
Describe the bug
For some unknown reason context is undefined in loader, but it was present in beforeLoad
Your Example Website or App
https://github.com/Arilas/tanter-bug
Steps to Reproduce the Bug or Issue
yarn
yarn dev
src/routes/_secured.tsx
Expected behavior
It should not clear the context
Screenshots or Videos
Platform
Additional context
I've over-simplified our case to the reproducible state. In our case we have a ServiceLocator with multiple factories, dependencies, events.
index.lazy.tsx
can be replaced with an route withbeforeLoad
which will have redirects, but it was an workaround to fix problem previously.