Closed luchsamapparat closed 2 weeks ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
auth-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 29, 2024 2:35pm |
@luchsamapparat is attempting to deploy a commit to the authjs Team on Vercel.
A member of the Team first needs to authorize it.
☕️ Reasoning
Usually, posting a message to a
BroadcastChannel
should not trigger themessage
event within the same window. However, if there two (or more)BroadcastChannel
instances within the same window, posting on one instance triggers themessage
event on all other instances.Wrapping
new Broadcast("next-auth")
in abroadcast()
function means that everybroadcast().postMessage(...)
call is done on a new instance. As a result, themessage
event listener, which sits on a differentBroadcastChannel
instance, calls__NEXTAUTH._getSession
within the same window - even thoughpostMessage
was probably called by agetSession
call in the first place.Also,
broadcast().removeEventListener(...)
inuseEffect
does not have any effect since it isn't called on theBroadcastChannel
instance on whichaddEventListener
has been called. In React'sStrictMode
all effects run twice in development, and since theunsubscribe
isn't working, there are two event listeners firing for each message event.🧢 Checklist