[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.
Sebastian Markbåge committed
Apr 3, 2025 at 10:06 UTC
b10cb4c01ec1ae41b67422239d919f261fefa7d1
1 file changed
+19
-1
packages/react-devtools-shared/src/backend/fiber/renderer.js
+19
-1
@@ -3345,13 +3345,31 @@ export function attach(
3345
fiberInstance.firstChild = null;
3346
}
3347
try {
3348
- if (nextFiber.tag === HostHoistable) {
3348
+ if (
3349
+ nextFiber.tag === HostHoistable &&
3350
+ prevFiber.memoizedState !== nextFiber.memoizedState
3351
+ ) {
3352
const nearestInstance = reconcilingParent;
3353
if (nearestInstance === null) {
3354
throw new Error('Did not expect a host hoistable to be the root');
3355
}
3356
releaseHostResource(nearestInstance, prevFiber.memoizedState);
3357
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);
3373
}
3374
3375
const isSuspense = nextFiber.tag === SuspenseComponent;