Skip to content

Commit

Permalink
Move and add try/catch to Host Single acquire
Browse files Browse the repository at this point in the history
The release is still not wrapped.
  • Loading branch information
sebmarkbage committed Sep 4, 2024
1 parent 7275edb commit 9c64bc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 15 additions & 0 deletions packages/react-reconciler/src/ReactFiberCommitHostEffects.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {
commitHydratedSuspenseInstance,
removeChildFromContainer,
removeChild,
clearSingleton,
acquireSingletonInstance,
} from './ReactFiberConfig';
import {captureCommitPhaseError} from './ReactFiberWorkLoop';

Expand Down Expand Up @@ -413,3 +415,16 @@ export function commitHostHydratedSuspense(
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
}

export function commitHostSingleton(finishedWork: Fiber) {
const singleton = finishedWork.stateNode;
const props = finishedWork.memoizedProps;

try {
// This was a new mount, we need to clear and set initial properties
clearSingleton(singleton);
acquireSingletonInstance(finishedWork.type, props, singleton, finishedWork);
} catch (error) {
captureCommitPhaseError(finishedWork, finishedWork.return, error);
}
}
14 changes: 2 additions & 12 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ import {
prepareForCommit,
beforeActiveInstanceBlur,
detachDeletedInstance,
clearSingleton,
acquireSingletonInstance,
releaseSingletonInstance,
getHoistableRoot,
acquireResource,
Expand Down Expand Up @@ -210,6 +208,7 @@ import {
commitHostHydratedSuspense,
commitHostRemoveChildFromContainer,
commitHostRemoveChild,
commitHostSingleton,
} from './ReactFiberCommitHostEffects';

// Used during the commit phase to track the state of the Offscreen component stack.
Expand Down Expand Up @@ -1852,16 +1851,7 @@ function commitMutationEffectsOnFiber(
if (flags & Update) {
const previousWork = finishedWork.alternate;
if (previousWork === null) {
const singleton = finishedWork.stateNode;
const props = finishedWork.memoizedProps;
// This was a new mount, we need to clear and set initial properties
clearSingleton(singleton);
acquireSingletonInstance(
finishedWork.type,
props,
singleton,
finishedWork,
);
commitHostSingleton(finishedWork);
}
}
}
Expand Down

0 comments on commit 9c64bc7

Please sign in to comment.