Skip to content
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

Route context not updated if new context is returned in beforeLoad #3051

Open
nklhtv opened this issue Dec 20, 2024 · 5 comments
Open

Route context not updated if new context is returned in beforeLoad #3051

nklhtv opened this issue Dec 20, 2024 · 5 comments

Comments

@nklhtv
Copy link
Contributor

nklhtv commented Dec 20, 2024

Which project does this relate to?

Router

Describe the bug

while updating from 1.45.4 to 1.91.3 i noticed a new behavior related to router context.
if a new context value is returned from beforeLoad it remains cached and new values for that same context key are not received.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-hsasr5ei?file=src%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. click "refresh" button ONCE

  2. auth.token and _auth.token have the same value

  3. click "refresh" button again

  4. auth.token and _auth.token have different values

  5. remove the return statement from the indexRoute's beforeLoad

  6. refresh the app and do 1. 2. & 3.

  7. the behavior is different. auth.token and _auth.token have the same value at all times

Expected behavior

each call to beforeLoad should receive the latest context even if some of the keys ware overridden by beforeLoad result in the previous call. this used to be the case in 1.45.4

Screenshots or Videos

Screen.Recording.2024-12-20.at.20.22.34.mov

Platform

  • OS: mac
  • Browser: firefox
  • Version: 130

Additional context

No response

@schiller-manuel
Copy link
Contributor

schiller-manuel commented Dec 20, 2024

can your create a minimal failing unit test case as a PR? still not fully understanding what's going on here

@nklhtv
Copy link
Contributor Author

nklhtv commented Dec 20, 2024

beforeLoad used to be called with match.routeContext:

context: routeContext,

but there is no routeContext since https://github.com/TanStack/router/pull/2104/files

@schiller-manuel
Copy link
Contributor

beforeLoad is called with the parent context
https://github.com/TanStack/router/blob/main/packages%2Freact-router%2Fsrc%2Frouter.ts#L2420

still don't understand how that was different or what you need here.

@nklhtv
Copy link
Contributor Author

nklhtv commented Dec 20, 2024

https://github.com/user-attachments/assets/b57854e5-2b6f-4b54-92dd-edf2971624cc
the issue is that beforeLoad gets called with cached values of context.auth even when the RouterProvider is rerendered with new context.auth. Is that clear?

@nklhtv
Copy link
Contributor Author

nklhtv commented Dec 20, 2024

beforeLoad is called with the parent context https://github.com/TanStack/router/blob/main/packages%2Freact-router%2Fsrc%2Frouter.ts#L2420

still don't understand how that was different or what you need here.

which i guess is a different value than routeContext from 1.45.4?
this.getMatch used to return both context: TAllContext and routeContext: TRouteContext

routeContext: TRouteContext

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants