Add StrictMode regression tests for useEchoNotification (#482)#522
Closed
naveentehrpariya wants to merge 1 commit into
Closed
Add StrictMode regression tests for useEchoNotification (#482)#522naveentehrpariya wants to merge 1 commit into
naveentehrpariya wants to merge 1 commit into
Conversation
Issue laravel#482 reported that the useEchoNotification callback was never invoked under React.StrictMode in v2.3.0: the cleanup unbound the notification listener, but an initializedRef guard prevented the remount from ever re-binding it. The guard was removed in the channel-subscription rework, which fixed the behavior, but nothing covers it. These tests mock the channel with real bind/unbind semantics and assert that a notification listener is still bound and the callback fires after StrictMode's mount/cleanup/remount cycle. They fail against the v2.3.0 implementation and pass on main.
Member
|
This feels like a lot of code. 😕 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #482.
While investigating #482 (
useEchoNotificationcallback never invoked underReact.StrictMode), I found the bug no longer reproduces on2.x:stopListeningForNotification(), but theinitializedRefguard inlisten()prevented the remount from ever re-binding it — the channel ended up with no notification listener, matching the report.2.x/ v2.3.5+: theinitializedRefguard was removed in the channel-subscription rework, so the remount re-binds correctly and the callback fires.Since nothing covered this, this PR adds regression tests. The mock implements real bind/unbind semantics (a
Setof bound listeners mutated bynotification()/stopListeningForNotification()), so the assertion checks what is actually still bound after the StrictMode cycle rather than just thatnotification()was called at some point:useEchoNotificationstill has a bound listener and invokes the callback after the StrictMode remount — fails against the v2.3.0 implementation, passes on2.x(verified by swapping in the olduse-echo.ts).useEchocontrol test covering the same cycle for regular events.#482 itself can likely be closed — the fix has shipped, the reporter was on 2.3.0.