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

fix(chore): replace use-context-selector context with React Context #20287

Merged

Conversation

simotae14
Copy link
Contributor

@simotae14 simotae14 commented May 9, 2024

What does it do?

Fix the issue we had after registration because the token was not updated correctly when we are redirected to the usecase page

Why is it needed?

With use-context-selector context when we save the token in the registration handler, using the setToken coming from the useAuth hook, the value is not immediately updated to be used in the PrivateRoute component so the UseCasePage page is not served

How to test it?

  • clean the db
  • create a new admin and flag and enable telemetry
  • check if the user is redirected to the /usecase page instead of the /admin

Related issue(s)/PR(s)

Related issue: #20345

@simotae14 simotae14 added source: core:admin Source is core/admin package pr: fix This PR is fixing a bug labels May 9, 2024
@simotae14 simotae14 requested a review from joshuaellis May 9, 2024 08:09
@simotae14 simotae14 self-assigned this May 9, 2024
@simotae14 simotae14 marked this pull request as draft May 9, 2024 08:09
@joshuaellis
Copy link
Member

From your PR description, it's not clear how you came to this change, can you explain it in detail? It's a very "big" change to make across the app because we loose selection performance, so good to understand it thoroughly :)

Copy link
Member

@joshuaellis joshuaellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great investigation. This would have been very tricky to debug, to do this properly we have a few options:

  1. remove use-context-selector as you have done, but also remove the selector function since it's pointless and verbose now.
  2. use a unique version with the Auth feature i.e. @radix-ui/react-context that doesn't have the selector used and would also solve the issue, but we do risk this quirk coming back for us in the future, although I don't think it will considering how unique this is to the router acting before react has updated.
  3. We could potentially pass the redirect query param a bit more and in login check if it's there and just do it if we dont actually need the user to login,

Let me know what you think!

Copy link

vercel bot commented May 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
contributor-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 1:54pm

@simotae14
Copy link
Contributor Author

Hey @joshuaellis , thanks a lot for your suggestions... In the end I decided to continue with solution 1 because it lets me use most of your code and just change some small parts in the code (remove the selectors).
If you are ok with this solution I can then create a new PR also in v5 to solve the same issue

@simotae14 simotae14 marked this pull request as ready for review May 13, 2024 13:42
@simotae14 simotae14 added this to the 4.24.3 milestone May 13, 2024
Copy link
Contributor

github-actions bot commented May 13, 2024

Size Change: -1.21 kB (-0.09%)

Total Size: 1.31 MB

Filename Size Change
examples/getstarted/build/main.********.js 1.3 MB -1.2 kB (-0.09%)
ℹ️ View Unchanged
Filename Size Change
examples/getstarted/build/bb4d0d527bdfb161bc5a.svg 2.33 kB 0 B
examples/getstarted/build/index.html 609 B +1 B (+0.16%)
examples/getstarted/build/runtime~main.********.js 4.21 kB -2 B (-0.05%)

compressed-size-action

@joshuaellis
Copy link
Member

If you are ok with this solution I can then create a new PR also in v5 to solve the same issue

we'll need to check there aren't performance regressions, but i'm sure it'll be fine :)

Copy link
Member

@joshuaellis joshuaellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code changes look fine ✅

Copy link
Contributor

@remidej remidej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did QA, merging now as Simone is OOO

@remidej remidej merged commit 0c9f2e7 into develop May 21, 2024
144 checks passed
@remidej remidej deleted the fix/replace-context-to-show-usecase-page-after-registration branch May 21, 2024 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:admin Source is core/admin package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants