-
-
Notifications
You must be signed in to change notification settings - Fork 783
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
Error thrown from beforeLoad
and handled through errorComponent
is ignored on initial request
#3462
Comments
any good workaround? This makes all URLs behind a login wall throw an error which is not ideal.... |
Having the exact same issue. It happens even on more trivial case, where I try to redirect in beforeLoad function.
Even when the user is null, it does not redirect but goes directly to the page that should be under authentication. |
One more thing, in the demo, when I try to change the beforeLoad function in _authed:
to loader function:
It works almost properly - atleast from user point of view, he will get the login component as he should. I know documentation recommends using the |
Which project does this relate to?
Start
Describe the bug
When an error is thrown from
beforeLoad
and handled througherrorComponent
it only works as expected on client navigation. When the page is reloaded/first requested the return forerrorComponent
is ignored andcomponent
/rest of the tree is rendered. This breaks many auth setups currently.Your Example Website or App
https://tanstack.com/start/latest/docs/framework/react/examples/start-basic-auth
Steps to Reproduce the Bug or Issue
This can be reproduced using the Start Basic Auth example.
This error is shown:
You can also add a
console.log
toapp/routes/_authed/posts.tsx
. This shows it tries to render the component, even though we are still unauthenticated andbeforeLoad
inapp/routes/_authed.tsx
throws an error which is handled byerrorComponent
, which should prevent rendering of the posts/component
.Expected behavior
When throwing an error from
beforeLoad
and handling it withinerrorComponent
thecomponent
should not be rendered – even on intial request handled by the server without client side navigation.Screenshots or Videos
start-before-load-error-component.mp4
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: