Skip to content

Add StrictMode regression tests for useEchoNotification (#482)#522

Closed
naveentehrpariya wants to merge 1 commit into
laravel:2.xfrom
naveentehrpariya:add-strict-mode-notification-test
Closed

Add StrictMode regression tests for useEchoNotification (#482)#522
naveentehrpariya wants to merge 1 commit into
laravel:2.xfrom
naveentehrpariya:add-strict-mode-notification-test

Conversation

@naveentehrpariya

Copy link
Copy Markdown

Related to #482.

While investigating #482 (useEchoNotification callback never invoked under React.StrictMode), I found the bug no longer reproduces on 2.x:

  • v2.3.0 (the reported version): on StrictMode's mount → cleanup → remount cycle, the cleanup unbound the notification listener via stopListeningForNotification(), but the initializedRef guard in listen() prevented the remount from ever re-binding it — the channel ended up with no notification listener, matching the report.
  • 2.x / v2.3.5+: the initializedRef guard 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 Set of bound listeners mutated by notification() / stopListeningForNotification()), so the assertion checks what is actually still bound after the StrictMode cycle rather than just that notification() was called at some point:

  • useEchoNotification still has a bound listener and invokes the callback after the StrictMode remount — fails against the v2.3.0 implementation, passes on 2.x (verified by swapping in the old use-echo.ts).
  • A useEcho control 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.

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.
@taylorotwell

Copy link
Copy Markdown
Member

This feels like a lot of code. 😕

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

Successfully merging this pull request may close these issues.

2 participants