Skip to content

Fix Activity hide detaching live siblings after an interrupted render - #38445

Open
CinchBlue wants to merge 1 commit into
react:mainfrom
CinchBlue:fix-activity-hide-detached-siblings
Open

CinchBlue wants to merge 1 commit into
react:mainfrom
CinchBlue:fix-activity-hide-detached-siblings

Conversation

@CinchBlue

Copy link
Copy Markdown

Summary

Fixes #38430.

If an <Activity> is hidden after a render that was interrupted, deleted DOM nodes can stay on screen, and a Suspense
fallback can be left next to its content.

On hide, recursivelyTraverseDisconnectPassiveEffects walks the committed tree. A fiber that still has a
ChildDeletion flag from an earlier commit goes through detachAlternateSiblings, which cuts the sibling links along
parentFiber.alternate.child. Suppose an earlier render cloned the parent and was interrupted before it began that
fiber. Then alternate.child === parentFiber.child, so the links being cut belong to the live children, and later
updates lose those siblings.

The fix skips the detach when both fibers point to the same child. In that case they are the current children, not the
previous ones.

How did you test this change?

Added packages/react-reconciler/src/__tests__/ReactActivityInterruptedHide-test.js. It interrupts a render, hides
the Activity, shows it again, and checks the rendered output.

yarn test --maxWorkers=2 -r=stable ReactActivityInterruptedHide
yarn test --maxWorkers=2 -r=stable --prod ReactActivityInterruptedHide
yarn test --maxWorkers=2 -r=experimental ReactActivityInterruptedHide
yarn test --maxWorkers=2 -r=experimental --prod ReactActivityInterruptedHide

The test passes in all four configs with the change. With only ReactFiberCommitWork.js reverted, it fails in all
four. yarn prettier made no changes, and yarn linc and yarn flow dom-node both pass.

I also checked a standalone page in headless Chrome and Firefox, using 19.3.1 and a canary build from edae846a9, in
development and production. The bug shows in each run, and a control case stays correct. I did not run the full
yarn test or the www/xplat flow targets.

When an Activity is hidden, passive effects are disconnected by walking the
committed tree. If a fiber still carries a ChildDeletion flag from an earlier
commit, detachAlternateSiblings clears the sibling pointers along
parentFiber.alternate.child.

If an earlier render cloned the parent but was interrupted before it began
that fiber, alternate.child === parentFiber.child. The links being cut are
then those of the live children, so later updates lose siblings: deleted DOM
nodes stay on screen and a Suspense fallback can remain beside its content.

Skip the detach when both fibers share the same child, since those are the
current children and not the previous ones. Adds a test that fails without
the change.

Fixes react#38430

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@meta-cla meta-cla Bot added the CLA Signed label Nov 29, 2026
@github-actions

Copy link
Copy Markdown

A size report will appear here when the build finishes.

Generated by sizebot against e8aba68

This branch has not been deployed

No deployments
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.

Bug: hiding an <Activity> after an interrupted render leaves deleted DOM nodes behind

1 participant