Repository navigation
[DevTools] Fix Fabric host-instance map leak when public instances are created lazily - #37758
boriskozak wants to merge 2 commits into
Conversation
…DevToolsInstanceMap
|
The build for this commit did not complete, so there is no size report. See the workflow run for details. Generated by sizebot against 2a50fc2 |
|
At head |
…exercise getHostInstanceKey The first test inserted and looked up through getPublicInstance, which this PR leaves unchanged, so after canonical.publicInstance is assigned the lookup returns undefined rather than the stored instance. Assert that miss explicitly, then key acquire/release by getHostInstanceKey and assert it returns the same canonical key before and after the lazy public instance assignment, so release finds and removes the acquire entry.
|
thanks, good catch... reworked the test to do both halves of that. it keys acquire/release by getHostInstanceKey now, asserts the getPublicInstance lookup comes back undefined after canonical.publicInstance gets assigned, and asserts the helper returns the same canonical key before and after, so release finds the entry and removes it. targeted test passes (3/3), flow is clean too |
Summary
In React Native's Fabric renderer, a host instance is a
{node, canonical}wrapper whosecanonical.publicInstanceis created lazily. The DevTools backend keyedpublicInstanceToDevToolsInstanceMapbygetPublicInstance(hostInstance), which returns the wrapper before lazy creation and the public instance after. So when an acquire ran before the public instance existed and the release ran after, the two used different keys, the release missed, and unmounted instances (with their Fibers) were retained indefinitely.This change keys the map by the stable
canonicalobject instead, through a newgetHostInstanceKey()helper inDevToolsNativeHost.js. Public instances passed back in viagetElementIDForHostInstance,getSuspenseNodeIDForHostInstance, andgetNearestMountedDOMNodeare normalized through__internalInstanceHandle.stateNode.canonicalto the same key. Paper (_nativeTag) and DOM (identity) keying are unchanged.Fixes #37752.
How did you test this change?
mainwith the realgetPublicInstancecode, simulating RN's lazycanonical.publicInstancecreation: the release lookup missed before the fix and hits after it.packages/react-devtools-shared/src/__tests__/hostInstanceMapKey-test.jscovering the mismatch repro, stable canonical keying before/after lazy public instance creation, public-instance lookup normalization, and unchanged Paper/DOM key behavior.Note: I could not run
yarn testlocally because dependency installation fails on this machine's network, so I verified against the real module code directly; the new test is included for CI.