-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Context is undefined after redirect #1531
Comments
Redirects were broken between 1.28.2 and 1.31.1, but on the side of the Router context, nothing has changed in that area in a LONG time. We'd need a working reproduction for us to be able to diagnose what specifically in your setup is breaking stuff for you. Also please confirm this issue you are facing on version 1.31.3 as well. You can create a reproduction using the Router file-based stackblitz starter. |
I tried to reproduce this and wasn't able to recreate this on my end with version 1.31.3. Here's my attempt: https://stackblitz.com/edit/github-dxj2gr |
@SeanCassiere Managed to repro: https://stackblitz.com/edit/github-dxj2gr-btjqhp |
I am having the same issue https://stackblitz.com/edit/github-dxj2gr-xfuqc1 Case 1
Case 2
|
@mintaka2479 By any change, do you have any workaround for this issue? Because it brokes login/logout on my website. Now after login and logout I have this issue and user has to reload the page to fix it |
Downgrading to |
Sometimes it also happens with loaderData |
For us, loaderData was fixed in 1.31.6. Context is still sometimes undefined though. |
I am on the latest version and contextI can reproduce in one place every time, but one time in console I see error with both content and loader data on latest version, but I don't know, may be something else caused it, because it was only one time on new version. As I use query, now I almost don't use loaderData, so, I cannot say more about it. But context issue is still happening and cause serious problems. As we still develop our app it is not a critical problem, but I hope it will be fixed soon |
I am experiencing this too - when redirecting from one route to another in |
Please recheck this. It's possible that this was inadvertently fixed with #1559. |
I'm still facing this problem. If I redirect the context becomes undefined. I'm on router version |
@SeanCassiere I have just tested on latest version and I am still facing this problem too |
The default options have been fixed. https://stackblitz.com/edit/github-dxj2gr-xfuqc1
console log
|
I don't have gcTime: 0. I have logout button. When user press on it, I remove auth token and make router.invalidate(), which causes throw redirect to login page in beforeLoad and in this moment context becomes undefined |
I have just tested one more time. Issue happening only if I do throw redirect(). In logic logic I have two options.
So, when I do router.history.push it works. If I do throw redirect(), I am facing undefined context issue, nothing changed for me with the latest version Issue also happens without router.invalidate() and etc. If I just go to home page anauthorised, what causes throw redirect() in my logic, it brakes with undefined context(video is from production build, in local build it shows like on screenshot) https://github.com/TanStack/router/assets/57814533/9bb4eacc-e4aa-4a3e-9752-874620ae9182 |
I can also confirm that this is not fixed for me. |
I've tried taking a stab at it since I've been facing this issue for a bit as well, but I'm hitting a wall. My issue is a bit different from the ones shared in the reproductions (can't share my code, and I haven't managed yet to create a repro), but basically context within loader (not beforeLoad, it's available there) is undefined after a redirect.
The unauthorized page redirects users from within a I'll try making a repro again, but in the meanwhile I hope this can help pinpoint the issue somehow 🤷♂️ |
@SeanCassiere By any change, do you know when will this be fixed approximately? It really makes a lot of problems in my app and, unfortunately, I cannot rollback to previous version, because there are other bugs there. |
I don't have the bandwidth to look into this until probably mid next week. @tannerlinsley any idea around where this bug would be happening? |
In the meantime here is a workaround
ugly but working on my side |
@freshgiammi this seems to do the trick. |
This should now be fixed with the 1.32.11 release. 📢 Huge shoutout to @freshgiammi for the fix. |
I'm so sorry to say this, but it still doesn't work for me with 1.32.11 :( This is the bug from hell, eh? |
@ccapndave a minimal reproduction will be needed for this to be looked into. You can create a minimal reproduction using the Router file-based stackblitz starter or Router code-based stackblitz starter. Please make sure your reproduction uses a minimum version of 1.32.11. Edit: I'll keep this open for a few days for anyone else who is still running into a problem matching this issue's description. |
1.32.11 fixes my issue/reproduction. Cheers! |
Unfortunately this isn't working for me in I've managed to create a repro in stackblitz: https://stackblitz.com/edit/github-kx4dql-mgkaub?file=src%2Froutes%2Fabout.tsx I think I've narrowed it down to something related to Repro steps:
Now if you remove StrictMode and retest the issue doesn't happen. |
That's certainly a weird one. I'm currently having trouble replicating this in a unit test. I'll have to leave this open until I get more bandwidth to get back to this. |
It is still not fixed for me. I tested on the latest version at issue still persists. I don't sure was it like that before or not,but, I checked in react router devtools and context is undefined in latest route match. In __root and $lang routes context is not undefined, but in $lang.login it is undefined 2024-05-17.17.19.01.mov |
Yeah, it looks like this issue might have been fixed only in part. Looks like this time it's this function throwing an error, which halts the flow and skips the context assignment to the matched route. I won't have time to dig deeper until next week so I'm dropping this here in case anyone wants to look into this issue 👋 |
I made a reproduction: |
The |
@callumbooth this problem has been fixed with the 1.32.16 release. @maksymskuibida please retest with 1.32.16 using @cpakken Your issue will tracked separately in #1618. This issue is already a bit too crowded. |
@SeanCassiere I've just tested and I can confirm that it is fixed for me now. throw redirect() redirects correctly and there is no undefined context anymore. |
My issue is also resolved, thank you 🎉 |
@SeanCassiere Sad to say we're still seeing context being undefined after upgrading to v1.33.4. Although, it has moved from initial load to when preloading other routes on hover. I'll try to create a minimal reproduction and will create a new issue for it. |
As promised, here's a new issue with reproduction: #1637 |
I found another edge case in Here's a complete repro: |
@mirague I opened an issue for that here #1656, maybe add your repro there as well? |
Describe the bug
I use authentication, similar to Authenticated Routes example from documentation. So, when user is on /$lang page, if user is not authorised, user is been redirecting to /$lang/login page. It happens, but useRouteContext returns undefined instead of context. I set context in RouterProvider like this. If I reload the page, issue disappears
I tested on 1.29.2, 1.30.1, 1.31.1, issue happens. I also tested on 1.26.21 and issue does not happen. I didn't test versions between 1.26.21 and 1.29.1
Your Example Website or App
https://admin.7loc.com/en
Steps to Reproduce the Bug or Issue
It happens in our live admin panel(admin panel at all is in development, but some functionality have already been implemented)
Expected behavior
Context, if it set in router provider is always available and not undefined
Screenshots or Videos
undefined.context.issue.mov
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: