Skip to content

Commit 9c64bc7

Browse files
committed
Move and add try/catch to Host Single acquire
The release is still not wrapped.
1 parent 7275edb commit 9c64bc7

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

packages/react-reconciler/src/ReactFiberCommitHostEffects.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ import {
4747
commitHydratedSuspenseInstance,
4848
removeChildFromContainer,
4949
removeChild,
50+
clearSingleton,
51+
acquireSingletonInstance,
5052
} from './ReactFiberConfig';
5153
import {captureCommitPhaseError} from './ReactFiberWorkLoop';
5254

@@ -413,3 +415,16 @@ export function commitHostHydratedSuspense(
413415
captureCommitPhaseError(finishedWork, finishedWork.return, error);
414416
}
415417
}
418+
419+
export function commitHostSingleton(finishedWork: Fiber) {
420+
const singleton = finishedWork.stateNode;
421+
const props = finishedWork.memoizedProps;
422+
423+
try {
424+
// This was a new mount, we need to clear and set initial properties
425+
clearSingleton(singleton);
426+
acquireSingletonInstance(finishedWork.type, props, singleton, finishedWork);
427+
} catch (error) {
428+
captureCommitPhaseError(finishedWork, finishedWork.return, error);
429+
}
430+
}

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ import {
121121
prepareForCommit,
122122
beforeActiveInstanceBlur,
123123
detachDeletedInstance,
124-
clearSingleton,
125-
acquireSingletonInstance,
126124
releaseSingletonInstance,
127125
getHoistableRoot,
128126
acquireResource,
@@ -210,6 +208,7 @@ import {
210208
commitHostHydratedSuspense,
211209
commitHostRemoveChildFromContainer,
212210
commitHostRemoveChild,
211+
commitHostSingleton,
213212
} from './ReactFiberCommitHostEffects';
214213

215214
// Used during the commit phase to track the state of the Offscreen component stack.
@@ -1852,16 +1851,7 @@ function commitMutationEffectsOnFiber(
18521851
if (flags & Update) {
18531852
const previousWork = finishedWork.alternate;
18541853
if (previousWork === null) {
1855-
const singleton = finishedWork.stateNode;
1856-
const props = finishedWork.memoizedProps;
1857-
// This was a new mount, we need to clear and set initial properties
1858-
clearSingleton(singleton);
1859-
acquireSingletonInstance(
1860-
finishedWork.type,
1861-
props,
1862-
singleton,
1863-
finishedWork,
1864-
);
1854+
commitHostSingleton(finishedWork);
18651855
}
18661856
}
18671857
}

0 commit comments

Comments
 (0)