Repository navigation
[DevTools] Release host instances deleted from a still-mounted component - #37847
LubabaKhalid wants to merge 1 commit into
Conversation
Host fibers are filtered by default, so they don't have a DevTools instance in the remaining set. When React deleted one while its nearest tracked instance stayed mounted, its entry in publicInstanceToDevToolsInstanceMap was never released, keeping the detached DOM node (and its subtree) alive until the page was reloaded. This happens with the extension installed even when DevTools is closed. Release filtered fibers listed in the parent's deletions while reconciling it, the same way untrackFiber already does for filtered children of an unmounted instance.
|
Hi @LubabaKhalid! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
|
No size report: this pull request only touches Generated by sizebot against 3d47157 |
Its done. Thanks |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
Hello @eps1lon, @huntie, @mondaychen, @jstejada, Status: Impact: Verification: Two asks: |

Summary
Fixes #37802.
With the React DevTools extension installed, DOM nodes that React removes from a component that stays mounted are kept alive by DevTools until the page reloads, even when DevTools is never opened. Examples are a component that swaps a keyed
<span>, or one that conditionally shows one.publicInstanceToDevToolsInstanceMapgets an entry for every host fiber on mount. Host fibers are filtered by default, so they have no DevTools instance of their own and are never inremainingReconcilingChildren. Their entries are only released fromuntrackFiber, which runs when the nearest tracked instance unmounts and only walks that fiber's current children. A host fiber deleted while its owner stays mounted is never visited, so its entry keeps the detached node and its subtree.This change releases the filtered fibers in
nextFiber.deletionswhile reconciling the parent, using the existinguntrackFiber, which also covers filtered descendants of the deleted subtree. Tracked instances in a deleted subtree are still unmounted through the remaining set as before. The release is skipped whenprevFiber === nextFiber, so a staledeletionsarray from an earlier commit is never read.How did you test this change?
I added a test to
store-test.js. It replaces a keyed<div><span /></div>in a mounted component, then removes it, and checks thatagent.getIDForHostInstanceno longer resolves the removed nodes. Without the fix it fails: the removed<div>still resolves to the mounted component.yarn build-for-devtools && yarn test --build --project devtools --release-channel=experimental: everything passes except the twoignoreList-test.jscases, which shell out toyarn build:chromeand fail in my local setup for unrelated reasons.yarn flow dom-nodepasses, and ESLint and Prettier pass on the changed files.