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

[Bug] Incorrect Redirection Behavior with Nested Routes in Solid Router #472

Open
zobweyt opened this issue Aug 17, 2024 · 2 comments
Open

Comments

@zobweyt
Copy link

zobweyt commented Aug 17, 2024

Describe the bug

I've encountered a strange behavior when using nested routes in my Solid Start application. Specifically, when I added an additional routes group and nested an authenticated route within it, the application started redirecting me to the login page instead of the expected home page ("/") after logging out.

As @Brendonovich mentioned in Discord:

  • It seems that $isAuthenticated may be becoming false before the redirect completes, causing the application to redirect back to the login page.
  • When an unauthenticated user navigates from / to /settings it logs "<Authenticated />", and then /settings/login redication happens but "<Authenticated /> cleanup" doesn't get called. Then, after pusing the "Login" button, /login to /settings redirection happens and "<Authenticated />" gets logged, then on logout "<Authenticated /> cleanup" gets called.
  • There appears to be a lingering reactive state (<Switch />/<Match /> still hanging around and being reactive) in the Solid Router that does not clean up properly after logging out, leading to unexpected behavior.

Also, try removing the /(group) folder and the (group).tsx and move everything to the root of the /routes folder. There won't be such behavior.

Your Example Website or App

https://github.com/zobweyt/solid-start-auth-example

Steps to Reproduce the Bug or Issue

  1. Ensure you're logged out and refreshed the page.
  2. Navigate to the /about or /settings route (protected). It will redirect you to the /login route as you're not authenticated.
  3. Log in with any credentials.
  4. Navigate to the /settings route (protected). It won't redirect you now as you're authenticated now.
  5. Push the "Logout" button on the /settings page.
  6. Observe the incorrect redirect behavior:
    1. Redirects to / first.
    2. Redirects to /login?redirect=%2F (unexpected).

Expected behavior

After logging out, it should redirect only to / and then not to /login.

Screenshots or Videos

Actual behavior

Video with steps to reproduce
2024-08-17.15-27-55.mp4
Missing console log

image

Expected behavior

Note, this is true when you'll remove the /(group) folder and the (group).tsx and move everything to the root of the /routes folder.

2024-08-17.16-22-24.mp4

image

Platform

  • OS: Microsoft Windows [Version 10.0.22621.4037]
  • Browser: Google Chrome [Version 127.0.6533.120]

Additional context

A common use case for implementing such groups is in scenarios where there is a sidebar navigation for an index page that is accessible to all users, regardless of their authentication status. Additionally, for protected routes, the sidebar should be also present, but it should not be displayed for such routes as /login or /register.

Related Issues

@ryansolid
Copy link
Member

Interesting.. This only seems to happen under a very specific set of steps. It is vital that you login on a page that was a redirect to the /settings page for this to happen. And I think that is where the bug is. It happens before we ever log in. There is a stranded /settings page. Why is interesting. I will look into it.

@ryansolid
Copy link
Member

ryansolid commented Sep 3, 2024

Yeah this is a bug in disposal in the core of Solid during Transitions. I will be working on a fix.

EDIT: it's here - solidjs/solid@e4b2c66
Will be released in the next version of Solid.

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