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

Component being rendered before beforeLoad() has completed #1827

Closed
JohnLowtherTA opened this issue Jun 25, 2024 · 2 comments · Fixed by #1907
Closed

Component being rendered before beforeLoad() has completed #1827

JohnLowtherTA opened this issue Jun 25, 2024 · 2 comments · Fixed by #1907
Labels
bug Something isn't working

Comments

@JohnLowtherTA
Copy link

JohnLowtherTA commented Jun 25, 2024

Describe the bug

After setting up a simple app with authentication, when I log in, the beforeLoad() function does not complete before my route is rendered. This causes an error as the context does not contain values I expect.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-ep72yj?file=src%2Froutes%2F_auth.dashboard.tsx

Steps to Reproduce the Bug or Issue

  1. Make sure you are in a logged out state
  2. Click on the second link 'Go to the auth-only dashboard page'
  3. Enter a username and click 'Login'

After an expected delay an error occurs. Since the beforeLoad() has not completed, the value property has not been added to the context.

Expected behavior

I would expect the beforeLoad() to finish running before the loader() runs or the component is rendered.

Screenshots or Videos

No response

Platform

  • OS: Windows
  • Browser: Edge
  • Version: 126.0.2592.68 (Official build) (64-bit)

Additional context

This issue seems to happen in part due to the fact that when the user logs in, the InnerApp (in main.tsx) rerenders due to a state update in the AuthContext. This results in the RouterProvider being re-rendered. This re-render happens in addition to the call to router.navigate() from the login.

@sarkis1231
Copy link

I have the same issue

@SeanCassiere SeanCassiere added the bug Something isn't working label Jul 4, 2024
@schiller-manuel
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
4 participants