Skip to content

Add regression tests for StrictMode transition unmount cleanup#36323

Open
Mouedrhiri wants to merge 1 commit intofacebook:mainfrom
Mouedrhiri:fix-36284-strictmode-cleanup
Open

Add regression tests for StrictMode transition unmount cleanup#36323
Mouedrhiri wants to merge 1 commit intofacebook:mainfrom
Mouedrhiri:fix-36284-strictmode-cleanup

Conversation

@Mouedrhiri
Copy link
Copy Markdown

Summary
This pull request adds regression coverage for issue #36284 about useEffect cleanup behavior when a component is unmounted during a transition under StrictMode with concurrent rendering.

Motivation:
The issue report describes an edge case where effect cleanup may be skipped, potentially causing leaked event listeners and duplicate subscriptions. Even though current behavior in the tested scenarios appears correct, this path did not have explicit focused regression protection for the exact StrictMode + transition unmount pattern.

What this PR changes:

Adds a StrictMode transition-unmount regression test at the reconciler level.
Adds a DOM-level regression test that mirrors the real-world pattern from the issue:
Effect registers a window event listener.
Component is unmounted using startTransition.
Test verifies listener is removed and cleanup is called.
No production runtime logic was changed in this PR.
This is a test-only hardening change to prevent future regressions.
Why this is valuable:

It codifies expected cleanup behavior in the exact scenario raised by the issue.
It protects both internal reconciler behavior and public DOM renderer behavior.
It improves confidence around StrictMode and concurrent transition unmount semantics.
How did you test this change?
I validated the change with focused targeted tests for the added regression coverage.

Commands run:

corepack yarn install --ignore-engines --force
corepack yarn test packages/react-reconciler/src/tests/ActivityStrictMode-test.js -t "calls passive cleanup when unmounting in a transition"
corepack yarn test packages/react-dom/src/tests/ReactDOMFiberAsync-test.js -t "calls effect cleanup when unmounting in a transition inside StrictMode"
Observed results:

Reconciler targeted test: PASS
React DOM targeted test: PASS
Both tests confirm cleanup executes and no post-unmount listener is left active in the tested StrictMode transition unmount scenarios.
Verification approach:

Assert cleanup is invoked on transition-driven unmount.
Assert a post-unmount event does not trigger the removed listener.
Account for StrictMode development double-invocation behavior in assertions.
Scope note:
I ran focused tests directly related to this fix. I did not run the full repository test suite, lint, Flow, or production test matrix in this local iteration.

@meta-cla meta-cla Bot added the CLA Signed label Apr 21, 2026
@react-sizebot
Copy link
Copy Markdown

Comparing: 94643c3...aef82ee

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB = 1.88 kB 1.88 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 612.96 kB 612.96 kB = 108.32 kB 108.32 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.84 kB 6.84 kB = 1.88 kB 1.88 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 678.89 kB 678.89 kB = 119.28 kB 119.28 kB
facebook-www/ReactDOM-prod.classic.js = 698.63 kB 698.63 kB = 122.75 kB 122.75 kB
facebook-www/ReactDOM-prod.modern.js = 688.94 kB 688.94 kB = 121.14 kB 121.13 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against aef82ee

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