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
beforeLoad
does not wait for async functions to resolve
#1553
Comments
It is worth checking this out in the |
I have the exact same issue for the exact same case. Would love a good answer there <3 |
Are you using |
Sandbox to reproduce: https://codesandbox.io/p/devbox/tanstack-router-before-load-with-query-8d9lcd
/posts/ works as expected |
@frederikvonsperling I imported your example into Stackblitz and it looks to be working with 1.32.5. https://stackblitz.com/edit/github-h31abz?file=src%2Fmain.tsx Can this please be retested. |
@SeanCassiere Same issue persists in 1.32.5 https://codesandbox.io/p/devbox/tanstack-router-before-load-with-query-8d9lcd going to /posts without trailing slash gives a white screen of death |
Looked further into this. The But a new bug has been found, as mentioned by @frederikvonsperling. The new bug found by @frederikvonsperling involves a combination of the I'll open a new issue for this new bug shortly. Edit: This has been fixed. |
The issue here is entirely related to the For example, consider the scenario where
Also, when
I've tested these behaviour here: https://stackblitz.com/edit/github-h31abz-hjnco9?file=src%2Fmain.tsx 📢 This doesn't happen when the 🧱 The default This is the created issue: #1591 |
Closing this as the correct bug shall be tracked in the issue mentioned. |
@SeanCassiere Sorry, but for me this issue still exists and is not related to See this repo for reproduction: CodeSandbox Steps to reproduce:
Tested with latest ( |
@nwi-di the beforeLoad is working correctly. It's just a https://codesandbox.io/p/devbox/nostalgic-cloud-d5s8zx?file=%2Fsrc%2Fauth.tsx%3A7%2C31 Edit: TLDR; The problem you are facing in your repro is not the |
So, you mean I need to await the |
The CSB link I posted earlier didn't seems to have all the changes I actually made. CSB has issues... Either ways I've updated the "authenticated routes" example on main. Once again, what you are experiencing is NOT about an asynchronous Also, a weird aside, non of the issues you've mentioned show up when testing with Stackblitz, pretty much only in CSB. |
Thanks for updating the example on main. I do not know why CSB has these issues at the moment... Ok, to get things in the right order, I am trying to understand the issue here in more detail... Due to the asynchronous request in the login function, the react state updates are put to the JS jobs queue, right? Without the asynchronous request they remain on the call stack and are handled directly, but with asynchronous request they are handled later. So here is one difference, right? Due to that, in the following promise chaining of the With the "sleep" you put into the example, the router invalidation and navigation are put behind the react updates (due to the |
You are more-or-less on the right track. React concurrent mode is also at play here, so the way it handles the batching of state updates can also come into play. I don't really use these kinds of auth flows in my apps, rather relying on oauth2 flows instead. So this is just a simple auth flow that I came up with a few months back just to demonstrate the router concepts. Don't look to copy the auth flow in the example. Rather just look at the concepts behind the usage of the Router's context, throws in the |
Describe the bug
I have the same setup as the Authenticated Routes examples, but with firebase authentication. I have my auth in context, with a login and logout function. I have an
_auth.tsx
file in the routes folder. Then a_auth
folder containing all protected routes.When the auth context is set in localStorage, same as the example, routing happens as expected. However when wanting to set the user from the result of the signIn function from firebase the
beforeLoad
does not wait for the result and the context in the_auth
file remains unchanged.Your Example Website or App
Steps to Reproduce the Bug or Issue
With the same setup as the Authenticated Routes example, the only change required would be to have something like firebase authentication and then changing
setStoredUser(username)
toExpected behavior
The
beforeLoad
should allow for resolved async values being set into contextScreenshots or Videos
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: