Skip to content

Commit b10cb4c

Browse files
authored
[DevTools] Release and aquire host instances when they're cloned in persistent mode (#32812)
In persistent mode they can change when they're closned and so we need to release the old copy and acquire the new copy.
1 parent f0c767e commit b10cb4c

File tree

1 file changed

+19
-1
lines changed
  • packages/react-devtools-shared/src/backend/fiber

1 file changed

+19
-1
lines changed

Diff for: packages/react-devtools-shared/src/backend/fiber/renderer.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -3345,13 +3345,31 @@ export function attach(
33453345
fiberInstance.firstChild = null;
33463346
}
33473347
try {
3348-
if (nextFiber.tag === HostHoistable) {
3348+
if (
3349+
nextFiber.tag === HostHoistable &&
3350+
prevFiber.memoizedState !== nextFiber.memoizedState
3351+
) {
33493352
const nearestInstance = reconcilingParent;
33503353
if (nearestInstance === null) {
33513354
throw new Error('Did not expect a host hoistable to be the root');
33523355
}
33533356
releaseHostResource(nearestInstance, prevFiber.memoizedState);
33543357
aquireHostResource(nearestInstance, nextFiber.memoizedState);
3358+
} else if (
3359+
(nextFiber.tag === HostComponent ||
3360+
nextFiber.tag === HostText ||
3361+
nextFiber.tag === HostSingleton) &&
3362+
prevFiber.stateNode !== nextFiber.stateNode
3363+
) {
3364+
// In persistent mode, it's possible for the stateNode to update with
3365+
// a new clone. In that case we need to release the old one and aquire
3366+
// new one instead.
3367+
const nearestInstance = reconcilingParent;
3368+
if (nearestInstance === null) {
3369+
throw new Error('Did not expect a host hoistable to be the root');
3370+
}
3371+
releaseHostInstance(nearestInstance, prevFiber.stateNode);
3372+
aquireHostInstance(nearestInstance, nextFiber.stateNode);
33553373
}
33563374

33573375
const isSuspense = nextFiber.tag === SuspenseComponent;

0 commit comments

Comments
 (0)