mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Use commitAllHostEffects() traversal for getSnapshotBeforeUpdate()
This commit is contained in:
+6
-51
@@ -321,6 +321,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
|||||||
recordEffect();
|
recordEffect();
|
||||||
|
|
||||||
const effectTag = nextEffect.effectTag;
|
const effectTag = nextEffect.effectTag;
|
||||||
|
|
||||||
|
if (effectTag & Snapshot) {
|
||||||
|
const current = nextEffect.alternate;
|
||||||
|
commitBeforeMutationLifeCycles(current, nextEffect);
|
||||||
|
}
|
||||||
|
|
||||||
if (effectTag & ContentReset) {
|
if (effectTag & ContentReset) {
|
||||||
commitResetTextContent(nextEffect);
|
commitResetTextContent(nextEffect);
|
||||||
}
|
}
|
||||||
@@ -378,22 +384,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function commitBeforeMutationLifecycles() {
|
|
||||||
while (nextEffect !== null) {
|
|
||||||
const effectTag = nextEffect.effectTag;
|
|
||||||
|
|
||||||
if (effectTag & Snapshot) {
|
|
||||||
recordEffect();
|
|
||||||
const current = nextEffect.alternate;
|
|
||||||
commitBeforeMutationLifeCycles(current, nextEffect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Don't cleanup effects yet;
|
|
||||||
// This will be done by commitAllLifeCycles()
|
|
||||||
nextEffect = nextEffect.nextEffect;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function commitAllLifeCycles(
|
function commitAllLifeCycles(
|
||||||
finishedRoot: FiberRoot,
|
finishedRoot: FiberRoot,
|
||||||
currentTime: ExpirationTime,
|
currentTime: ExpirationTime,
|
||||||
@@ -501,41 +491,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
|||||||
|
|
||||||
prepareForCommit(root.containerInfo);
|
prepareForCommit(root.containerInfo);
|
||||||
|
|
||||||
// Invoke instances of getSnapshotBeforeUpdate before mutation.
|
|
||||||
nextEffect = firstEffect;
|
|
||||||
// TODO Start new commit phase timer from ReactDebugFiberPerf
|
|
||||||
while (nextEffect !== null) {
|
|
||||||
let didError = false;
|
|
||||||
let error;
|
|
||||||
if (__DEV__) {
|
|
||||||
invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
|
|
||||||
if (hasCaughtError()) {
|
|
||||||
didError = true;
|
|
||||||
error = clearCaughtError();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
commitBeforeMutationLifecycles();
|
|
||||||
} catch (e) {
|
|
||||||
didError = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (didError) {
|
|
||||||
invariant(
|
|
||||||
nextEffect !== null,
|
|
||||||
'Should have next effect. This error is likely caused by a bug ' +
|
|
||||||
'in React. Please file an issue.',
|
|
||||||
);
|
|
||||||
onCommitPhaseError(nextEffect, error);
|
|
||||||
// Clean-up
|
|
||||||
if (nextEffect !== null) {
|
|
||||||
nextEffect = nextEffect.nextEffect;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO Stop new commit phase timer from ReactDebugFiberPerf
|
|
||||||
|
|
||||||
// Commit all the side-effects within a tree. We'll do this in two passes.
|
// Commit all the side-effects within a tree. We'll do this in two passes.
|
||||||
// The first pass performs all the host insertions, updates, deletions and
|
// The first pass performs all the host insertions, updates, deletions and
|
||||||
// ref unmounts.
|
// ref unmounts.
|
||||||
|
|||||||
Reference in New Issue
Block a user