Skip to content

Commit db84b9a

Browse files
committed
Use commitAllHostEffects() traversal for getSnapshotBeforeUpdate()
1 parent 0f984ac commit db84b9a

File tree

1 file changed

+6
-51
lines changed

1 file changed

+6
-51
lines changed

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
321321
recordEffect();
322322

323323
const effectTag = nextEffect.effectTag;
324+
325+
if (effectTag & Snapshot) {
326+
const current = nextEffect.alternate;
327+
commitBeforeMutationLifeCycles(current, nextEffect);
328+
}
329+
324330
if (effectTag & ContentReset) {
325331
commitResetTextContent(nextEffect);
326332
}
@@ -378,22 +384,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
378384
}
379385
}
380386

381-
function commitBeforeMutationLifecycles() {
382-
while (nextEffect !== null) {
383-
const effectTag = nextEffect.effectTag;
384-
385-
if (effectTag & Snapshot) {
386-
recordEffect();
387-
const current = nextEffect.alternate;
388-
commitBeforeMutationLifeCycles(current, nextEffect);
389-
}
390-
391-
// Don't cleanup effects yet;
392-
// This will be done by commitAllLifeCycles()
393-
nextEffect = nextEffect.nextEffect;
394-
}
395-
}
396-
397387
function commitAllLifeCycles(
398388
finishedRoot: FiberRoot,
399389
currentTime: ExpirationTime,
@@ -501,41 +491,6 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
501491

502492
prepareForCommit(root.containerInfo);
503493

504-
// Invoke instances of getSnapshotBeforeUpdate before mutation.
505-
nextEffect = firstEffect;
506-
// TODO Start new commit phase timer from ReactDebugFiberPerf
507-
while (nextEffect !== null) {
508-
let didError = false;
509-
let error;
510-
if (__DEV__) {
511-
invokeGuardedCallback(null, commitBeforeMutationLifecycles, null);
512-
if (hasCaughtError()) {
513-
didError = true;
514-
error = clearCaughtError();
515-
}
516-
} else {
517-
try {
518-
commitBeforeMutationLifecycles();
519-
} catch (e) {
520-
didError = true;
521-
error = e;
522-
}
523-
}
524-
if (didError) {
525-
invariant(
526-
nextEffect !== null,
527-
'Should have next effect. This error is likely caused by a bug ' +
528-
'in React. Please file an issue.',
529-
);
530-
onCommitPhaseError(nextEffect, error);
531-
// Clean-up
532-
if (nextEffect !== null) {
533-
nextEffect = nextEffect.nextEffect;
534-
}
535-
}
536-
}
537-
// TODO Stop new commit phase timer from ReactDebugFiberPerf
538-
539494
// Commit all the side-effects within a tree. We'll do this in two passes.
540495
// The first pass performs all the host insertions, updates, deletions and
541496
// ref unmounts.

0 commit comments

Comments
 (0)