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(react): getSession should update session on current tab #11470

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

kracas
Copy link
Contributor

@kracas kracas commented Jul 27, 2024

☕️ Reasoning

Calling getSession should trigger refetch of session by broadcasting a message. However, since the broadcast channel was changed to a single instance in #10762, the broadcast channel instance that sends the message will not receive it and will not update the SessionProvider context on the current tab because this is how BroadcastChannel is supposed to work as specified in the specs:

Sends the given message to other BroadcastChannel objects set up for this channel

This commit creates a new BroadcastChannel instance just for posting a message. This message is received by all other BroadcastChannel instances that have EventListener, including the instance on the current tab. This message triggers __NEXTAUTH._getSession and updates the session on all tabs.

It does not break #10762, because the new instance is only used to post a message and no new EventListener is created, therefore no unnecessary /session requests are made.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

Could possibly fix

#11075 #9504 #11075

@kracas kracas requested a review from ThangHuuVu as a code owner July 27, 2024 07:13
Copy link

vercel bot commented Jul 27, 2024

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

Name Status Preview Comments Updated (UTC)
auth-docs ❌ Failed (Inspect) Jul 28, 2024 6:05am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Jul 28, 2024 6:05am

Copy link

vercel bot commented Jul 27, 2024

@kracas is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@balazsorban44 balazsorban44 merged commit fba3a14 into nextauthjs:main Aug 8, 2024
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants