-
-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useRouteContext
returns undefined
upon full page reload
#2010
Comments
Here is a workaround: const router = createRouter({
...
});
+ router.buildAndCommitLocation({});
+ // but... why? |
I can't remember where else we discussed this, but
Proposed solution:
|
This is not SSR related. just an ordinary SPA. |
Sorry, you are correct. This should be working for non-SSR renderings. However, the issue stands. What should we do? |
Removing the user access to the This sort of pattern is pretty handy and IMO it would be a shame to lose. // src/routes/posts.tsx
import { createFileRoute } from '@tanstack/react-router';
import { useSuspenseQuery, queryOptions } from '@tanstack/react-query';
export const Route = createFileRoute('/posts')({
beforeLoad: ({ params }) => {
return { // only calculate what the queryOptions were once
postOptions: queryOptions({ queryKey: ['posts', params.postId], ... }),
postCommentsOptions: queryOptions({ queryKey: ['posts', params.postId, 'comments'], ... })
}
},
loader: async ({ context }) => {
await Promise.allSettled([ // you can also choose not to await here, just kick off Query
context.queryClient.ensureQueryData(context.postOptions),
context.queryClient.ensureQueryData(context.postCommentsOptions),
])
},
component: Posts
})
function Posts() {
const { postOptions, postCommentOptions } = Route.useRouteContext();
const postQuery = useSuspenseQuery(postOptions);
const postCommentsQuery = useSuspenseQuery(postCommentsOptions);
// ...
} |
If I remember correctly, for a period of time during the beta when the 👆🏼Would something like this be feasible here?
|
reproducer in #2045 |
this is fixed in 1.49.1 |
Describe the bug
Upon full page reload,
useRouteContext
returnsundefined
.Your Example Website or App
https://stackblitz.com/edit/tanstack-router-qqb8ia?file=src%2Froutes%2Ffoo%2Findex.tsx&preset=node
Steps to Reproduce the Bug or Issue
Expected behavior
route context is never undefined
Screenshots or Videos
Screen.Recording.2024-07-22.at.22.31.33.mov
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: