mirror of
https://github.com/facebook/react.git
synced 2026-02-25 05:03:03 +00:00
Use commitAllHostEffects() traversal for getSnapshotBeforeUpdate()
This commit is contained in:
@@ -321,6 +321,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
||||
recordEffect();
|
||||
|
||||
const effectTag = nextEffect.effectTag;
|
||||
|
||||
if (effectTag & Snapshot) {
|
||||
const current = nextEffect.alternate;
|
||||
commitBeforeMutationLifeCycles(current, nextEffect);
|
||||
}
|
||||
|
||||
if (effectTag & ContentReset) {
|
||||
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(
|
||||
finishedRoot: FiberRoot,
|
||||
currentTime: ExpirationTime,
|
||||
@@ -501,41 +491,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
||||
|
||||
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.
|
||||
// The first pass performs all the host insertions, updates, deletions and
|
||||
// ref unmounts.
|
||||
|
||||
Reference in New Issue
Block a user