Skip to content

Commit 1033552

Browse files
author
Brian Vaughn
committed
Improved deletions approach
Process deletions as we traverse the tree during commit, before we process other effects. This has the result of better mimicking the previous sequencing.
1 parent 5cdbbba commit 1033552

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,6 +2125,8 @@ function commitRootImpl(root, renderPriorityLevel) {
21252125
}
21262126

21272127
function commitBeforeMutationEffects(fiber: Fiber) {
2128+
commitBeforeMutationEffectsDeletions(fiber.deletions);
2129+
21282130
if (fiber.child !== null) {
21292131
const primarySubtreeTag =
21302132
fiber.subtreeTag & (Deletion | Snapshot | Passive | Placement);
@@ -2159,15 +2161,6 @@ function commitBeforeMutationEffectsImpl(fiber: Fiber) {
21592161
const effectTag = fiber.effectTag;
21602162

21612163
if (!shouldFireAfterActiveInstanceBlur && focusedInstanceHandle !== null) {
2162-
// The "deletions" array on a Fiber holds previous children that were marked for deletion.
2163-
// However the overall commit sequence relies on child deletions being processed before parent's effects,
2164-
// so to satisfy that we also process the parent's "deletions" array (the deletion of siblings).
2165-
commitBeforeMutationEffectsDeletions(fiber.deletions);
2166-
const parent = fiber.return;
2167-
if (parent) {
2168-
commitBeforeMutationEffectsDeletions(parent.deletions);
2169-
}
2170-
21712164
// Check to see if the focused element was inside of a hidden (Suspense) subtree.
21722165
// TODO: Move this out of the hot path using a dedicated effect tag.
21732166
if (
@@ -2220,6 +2213,8 @@ function commitMutationEffects(
22202213
root: FiberRoot,
22212214
renderPriorityLevel,
22222215
) {
2216+
commitMutationEffectsDeletions(fiber.deletions, root, renderPriorityLevel);
2217+
22232218
if (fiber.child !== null) {
22242219
const primarySubtreeTag =
22252220
fiber.subtreeTag &
@@ -2262,15 +2257,6 @@ function commitMutationEffectsImpl(
22622257
root: FiberRoot,
22632258
renderPriorityLevel,
22642259
) {
2265-
// The "deletions" array on a Fiber holds previous children that were marked for deletion.
2266-
// However the overall commit sequence relies on child deletions being processed before parent's effects,
2267-
// so to satisfy that we also process the parent's "deletions" array (the deletion of siblings).
2268-
commitMutationEffectsDeletions(fiber.deletions, root, renderPriorityLevel);
2269-
const parent = fiber.return;
2270-
if (parent) {
2271-
commitMutationEffectsDeletions(parent.deletions, root, renderPriorityLevel);
2272-
}
2273-
22742260
const effectTag = fiber.effectTag;
22752261
if (effectTag & ContentReset) {
22762262
commitResetTextContent(fiber);

packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,31 +1732,15 @@ describe('ReactSuspenseWithNoopRenderer', () => {
17321732
await resolveText('B2');
17331733

17341734
expect(Scheduler).toHaveYielded(['Promise resolved [B2]']);
1735-
1736-
// Slight sequencing difference between old and new reconcilers,
1737-
// because walking the tree during the commit phase means processing deletions
1738-
// as part of processing the parent rather than the child.
1739-
gate(flags =>
1740-
flags.new
1741-
? expect(Scheduler).toFlushAndYield([
1742-
'B2',
1743-
'Destroy Layout Effect [B]',
1744-
'Destroy Layout Effect [Loading...]',
1745-
'Layout Effect [B2]',
1746-
'Destroy Effect [Loading...]',
1747-
'Destroy Effect [B]',
1748-
'Effect [B2]',
1749-
])
1750-
: expect(Scheduler).toFlushAndYield([
1751-
'B2',
1752-
'Destroy Layout Effect [Loading...]',
1753-
'Destroy Layout Effect [B]',
1754-
'Layout Effect [B2]',
1755-
'Destroy Effect [Loading...]',
1756-
'Destroy Effect [B]',
1757-
'Effect [B2]',
1758-
]),
1759-
);
1735+
expect(Scheduler).toFlushAndYield([
1736+
'B2',
1737+
'Destroy Layout Effect [Loading...]',
1738+
'Destroy Layout Effect [B]',
1739+
'Layout Effect [B2]',
1740+
'Destroy Effect [Loading...]',
1741+
'Destroy Effect [B]',
1742+
'Effect [B2]',
1743+
]);
17601744
});
17611745

17621746
it('suspends for longer if something took a long (CPU bound) time to render', async () => {

0 commit comments

Comments
 (0)