[Fiber] Move runWithFiberInDEV from CommitWork to CommitEffects (#30882)
Stacked on #30881. Move `runWithFiberInDEV` from the recursive part of the commit phase and instead wrap each call into user space. These should really map 1:1 with where we're using `try/catch` since that's where we're calling into user space. The goal of this is to avoid the extra stack frames added by `enableOwnerStacks` in the recursive parts to avoid stack overflow. This way we only have a couple of extra at the end of the stack instead of a couple of extra at every depth of the tree.
Sebastian Markbåge committed
Sep 5, 2024 at 20:54 UTC
a03254bc60b06c535c37e43c53b1fd40757b2ef4
4 files changed
+386
-251
packages/react-reconciler/src/ReactFiberCommitEffects.js
+183
-59
@@ -75,6 +75,8 @@ import {
75
callDestroyInDEV,
76
} from './ReactFiberCallUserSpace';
77
78
+import {runWithFiberInDEV} from './ReactCurrentFiber';
79
+
80
function shouldProfile(current: Fiber): boolean {
81
return (
82
enableProfilerTimer &&
@@ -128,7 +130,7 @@ export function commitHookEffectListMount(
130
if ((flags & HookInsertion) !== NoHookEffect) {
131
setIsRunningInsertionEffect(true);
132
}
131
- destroy = callCreateInDEV(effect);
133
+ destroy = runWithFiberInDEV(finishedWork, callCreateInDEV, effect);
134
if ((flags & HookInsertion) !== NoHookEffect) {
135
setIsRunningInsertionEffect(false);
136
}
@@ -182,9 +184,16 @@ export function commitHookEffectListMount(
184
} else {
185
addendum = ' You returned: ' + destroy;
186
}
185
- console.error(
186
- '%s must not return anything besides a function, ' +
187
- 'which is used for clean-up.%s',
187
+ runWithFiberInDEV(
188
+ finishedWork,
189
+ (n, a) => {
190
+ console.error(
191
+ '%s must not return anything besides a function, ' +
192
+ 'which is used for clean-up.%s',
193
+ n,
194
+ a,
195
+ );
196
+ },
197
hookName,
198
addendum,
199
);
@@ -330,7 +339,12 @@ export function commitClassLayoutLifecycles(
339
if (shouldProfile(finishedWork)) {
340
startLayoutEffectTimer();
341
if (__DEV__) {
333
- callComponentDidMountInDEV(finishedWork, instance);
342
+ runWithFiberInDEV(
343
+ finishedWork,
344
+ callComponentDidMountInDEV,
345
+ finishedWork,
346
+ instance,
347
+ );
348
} else {
349
try {
350
instance.componentDidMount();
@@ -341,7 +355,12 @@ export function commitClassLayoutLifecycles(
355
recordLayoutEffectDuration(finishedWork);
356
} else {
357
if (__DEV__) {
344
- callComponentDidMountInDEV(finishedWork, instance);
358
+ runWithFiberInDEV(
359
+ finishedWork,
360
+ callComponentDidMountInDEV,
361
+ finishedWork,
362
+ instance,
363
+ );
364
} else {
365
try {
366
instance.componentDidMount();
@@ -391,7 +410,9 @@ export function commitClassLayoutLifecycles(
410
if (shouldProfile(finishedWork)) {
411
startLayoutEffectTimer();
412
if (__DEV__) {
394
- callComponentDidUpdateInDEV(
413
+ runWithFiberInDEV(
414
+ finishedWork,
415
+ callComponentDidUpdateInDEV,
416
finishedWork,
417
instance,
418
prevProps,
@@ -412,7 +433,9 @@ export function commitClassLayoutLifecycles(
433
recordLayoutEffectDuration(finishedWork);
434
} else {
435
if (__DEV__) {
415
- callComponentDidUpdateInDEV(
436
+ runWithFiberInDEV(
437
+ finishedWork,
438
+ callComponentDidUpdateInDEV,
439
finishedWork,
440
instance,
441
prevProps,
@@ -439,7 +462,12 @@ export function commitClassDidMount(finishedWork: Fiber) {
462
const instance = finishedWork.stateNode;
463
if (typeof instance.componentDidMount === 'function') {
464
if (__DEV__) {
442
- callComponentDidMountInDEV(finishedWork, instance);
465
+ runWithFiberInDEV(
466
+ finishedWork,
467
+ callComponentDidMountInDEV,
468
+ finishedWork,
469
+ instance,
470
+ );
471
} else {
472
try {
473
instance.componentDidMount();
@@ -489,7 +517,11 @@ export function commitClassCallbacks(finishedWork: Fiber) {
517
// but instead we rely on them being set during last render.
518
// TODO: revisit this when we implement resuming.
519
try {
492
- commitCallbacks(updateQueue, instance);
520
+ if (__DEV__) {
521
+ runWithFiberInDEV(finishedWork, commitCallbacks, updateQueue, instance);
522
+ } else {
523
+ commitCallbacks(updateQueue, instance);
524
+ }
525
} catch (error) {
526
captureCommitPhaseError(finishedWork, finishedWork.return, error);
527
}
@@ -504,7 +536,16 @@ export function commitClassHiddenCallbacks(finishedWork: Fiber) {
536
if (updateQueue !== null) {
537
const instance = finishedWork.stateNode;
538
try {
507
- commitHiddenCallbacks(updateQueue, instance);
539
+ if (__DEV__) {
540
+ runWithFiberInDEV(
541
+ finishedWork,
542
+ commitHiddenCallbacks,
543
+ updateQueue,
544
+ instance,
545
+ );
546
+ } else {
547
+ commitHiddenCallbacks(updateQueue, instance);
548
+ }
549
} catch (error) {
550
captureCommitPhaseError(finishedWork, finishedWork.return, error);
551
}
@@ -530,7 +571,11 @@ export function commitRootCallbacks(finishedWork: Fiber) {
571
}
572
}
573
try {
533
- commitCallbacks(updateQueue, instance);
574
+ if (__DEV__) {
575
+ runWithFiberInDEV(finishedWork, commitCallbacks, updateQueue, instance);
576
+ } else {
577
+ commitCallbacks(updateQueue, instance);
578
+ }
579
} catch (error) {
580
captureCommitPhaseError(finishedWork, finishedWork.return, error);
581
}
@@ -542,6 +587,14 @@ if (__DEV__) {
587
didWarnAboutUndefinedSnapshotBeforeUpdate = new Set();
588
}
589
590
+function callGetSnapshotBeforeUpdates(
591
+ instance: any,
592
+ prevProps: any,
593
+ prevState: any,
594
+) {
595
+ return instance.getSnapshotBeforeUpdate(prevProps, prevState);
596
+}
597
+
598
export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
599
const prevProps = current.memoizedProps;
600
const prevState = current.memoizedState;
@@ -578,25 +631,38 @@ export function commitClassSnapshot(finishedWork: Fiber, current: Fiber) {
631
}
632
}
633
try {
581
- const snapshot = instance.getSnapshotBeforeUpdate(
582
- resolveClassComponentProps(
583
- finishedWork.type,
584
- prevProps,
585
- finishedWork.elementType === finishedWork.type,
586
- ),
587
- prevState,
634
+ const resolvedPrevProps = resolveClassComponentProps(
635
+ finishedWork.type,
636
+ prevProps,
637
+ finishedWork.elementType === finishedWork.type,
638
);
639
+ let snapshot;
640
if (__DEV__) {
641
+ snapshot = runWithFiberInDEV(
642
+ finishedWork,
643
+ callGetSnapshotBeforeUpdates,
644
+ instance,
645
+ resolvedPrevProps,
646
+ prevState,
647
+ );
648
const didWarnSet =
649
((didWarnAboutUndefinedSnapshotBeforeUpdate: any): Set<mixed>);
650
if (snapshot === undefined && !didWarnSet.has(finishedWork.type)) {
651
didWarnSet.add(finishedWork.type);
594
- console.error(
595
- '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +
596
- 'must be returned. You have returned undefined.',
597
- getComponentNameFromFiber(finishedWork),
598
- );
652
+ runWithFiberInDEV(finishedWork, () => {
653
+ console.error(
654
+ '%s.getSnapshotBeforeUpdate(): A snapshot value (or null) ' +
655
+ 'must be returned. You have returned undefined.',
656
+ getComponentNameFromFiber(finishedWork),
657
+ );
658
+ });
659
}
660
+ } else {
661
+ snapshot = callGetSnapshotBeforeUpdates(
662
+ instance,
663
+ resolvedPrevProps,
664
+ prevState,
665
+ );
666
}
667
instance.__reactInternalSnapshotBeforeUpdate = snapshot;
668
} catch (error) {
@@ -619,7 +685,13 @@ export function safelyCallComponentWillUnmount(
685
if (shouldProfile(current)) {
686
startLayoutEffectTimer();
687
if (__DEV__) {
622
- callComponentWillUnmountInDEV(current, nearestMountedAncestor, instance);
688
+ runWithFiberInDEV(
689
+ current,
690
+ callComponentWillUnmountInDEV,
691
+ current,
692
+ nearestMountedAncestor,
693
+ instance,
694
+ );
695
} else {
696
try {
697
instance.componentWillUnmount();
@@ -630,7 +702,13 @@ export function safelyCallComponentWillUnmount(
702
recordLayoutEffectDuration(current);
703
} else {
704
if (__DEV__) {
633
- callComponentWillUnmountInDEV(current, nearestMountedAncestor, instance);
705
+ runWithFiberInDEV(
706
+ current,
707
+ callComponentWillUnmountInDEV,
708
+ current,
709
+ nearestMountedAncestor,
710
+ instance,
711
+ );
712
} else {
713
try {
714
instance.componentWillUnmount();
@@ -697,7 +775,11 @@ export function safelyAttachRef(
775
nearestMountedAncestor: Fiber | null,
776
) {
777
try {
700
- commitAttachRef(current);
778
+ if (__DEV__) {
779
+ runWithFiberInDEV(current, commitAttachRef, current);
780
+ } else {
781
+ commitAttachRef(current);
782
+ }
783
} catch (error) {
784
captureCommitPhaseError(current, nearestMountedAncestor, error);
785
}
@@ -716,12 +798,20 @@ export function safelyDetachRef(
798
if (shouldProfile(current)) {
799
try {
800
startLayoutEffectTimer();
719
- refCleanup();
801
+ if (__DEV__) {
802
+ runWithFiberInDEV(current, refCleanup);
803
+ } else {
804
+ refCleanup();
805
+ }
806
} finally {
807
recordLayoutEffectDuration(current);
808
}
809
} else {
724
- refCleanup();
810
+ if (__DEV__) {
811
+ runWithFiberInDEV(current, refCleanup);
812
+ } else {
813
+ refCleanup();
814
+ }
815
}
816
} catch (error) {
817
captureCommitPhaseError(current, nearestMountedAncestor, error);
@@ -738,12 +828,20 @@ export function safelyDetachRef(
828
if (shouldProfile(current)) {
829
try {
830
startLayoutEffectTimer();
741
- ref(null);
831
+ if (__DEV__) {
832
+ (runWithFiberInDEV(current, ref, null): void);
833
+ } else {
834
+ ref(null);
835
+ }
836
} finally {
837
recordLayoutEffectDuration(current);
838
}
839
} else {
746
- ref(null);
840
+ if (__DEV__) {
841
+ (runWithFiberInDEV(current, ref, null): void);
842
+ } else {
843
+ ref(null);
844
+ }
845
}
846
} catch (error) {
847
captureCommitPhaseError(current, nearestMountedAncestor, error);
@@ -761,7 +859,13 @@ export function safelyCallDestroy(
859
destroy: () => void,
860
) {
861
if (__DEV__) {
764
- callDestroyInDEV(current, nearestMountedAncestor, destroy);
862
+ runWithFiberInDEV(
863
+ current,
864
+ callDestroyInDEV,
865
+ current,
866
+ nearestMountedAncestor,
867
+ destroy,
868
+ );
869
} else {
870
try {
871
destroy();
@@ -771,6 +875,44 @@ export function safelyCallDestroy(
875
}
876
}
877
878
+function commitProfiler(
879
+ finishedWork: Fiber,
880
+ current: Fiber | null,
881
+ commitTime: number,
882
+ effectDuration: number,
883
+) {
884
+ const {onCommit, onRender} = finishedWork.memoizedProps;
885
+
886
+ let phase = current === null ? 'mount' : 'update';
887
+ if (enableProfilerNestedUpdatePhase) {
888
+ if (isCurrentUpdateNested()) {
889
+ phase = 'nested-update';
890
+ }
891
+ }
892
+
893
+ if (typeof onRender === 'function') {
894
+ onRender(
895
+ finishedWork.memoizedProps.id,
896
+ phase,
897
+ finishedWork.actualDuration,
898
+ finishedWork.treeBaseDuration,
899
+ finishedWork.actualStartTime,
900
+ commitTime,
901
+ );
902
+ }
903
+
904
+ if (enableProfilerCommitHooks) {
905
+ if (typeof onCommit === 'function') {
906
+ onCommit(
907
+ finishedWork.memoizedProps.id,
908
+ phase,
909
+ effectDuration,
910
+ commitTime,
911
+ );
912
+ }
913
+ }
914
+}
915
+
916
export function commitProfilerUpdate(
917
finishedWork: Fiber,
918
current: Fiber | null,
@@ -779,35 +921,17 @@ export function commitProfilerUpdate(
921
) {
922
if (enableProfilerTimer && getExecutionContext() & CommitContext) {
923
try {
782
- const {onCommit, onRender} = finishedWork.memoizedProps;
783
-
784
- let phase = current === null ? 'mount' : 'update';
785
- if (enableProfilerNestedUpdatePhase) {
786
- if (isCurrentUpdateNested()) {
787
- phase = 'nested-update';
788
- }
789
- }
790
-
791
- if (typeof onRender === 'function') {
792
- onRender(
793
- finishedWork.memoizedProps.id,
794
- phase,
795
- finishedWork.actualDuration,
796
- finishedWork.treeBaseDuration,
797
- finishedWork.actualStartTime,
924
+ if (__DEV__) {
925
+ runWithFiberInDEV(
926
+ finishedWork,
927
+ commitProfiler,
928
+ finishedWork,
929
+ current,
930
commitTime,
931
+ effectDuration,
932
);
800
- }
801
-
802
- if (enableProfilerCommitHooks) {
803
- if (typeof onCommit === 'function') {
804
- onCommit(
805
- finishedWork.memoizedProps.id,
806
- phase,
807
- effectDuration,
808
- commitTime,
809
- );
810
- }
933
+ } else {
934
+ commitProfiler(finishedWork, current, commitTime, effectDuration);
935
}
936
} catch (error) {
937
captureCommitPhaseError(finishedWork, finishedWork.return, error);
packages/react-reconciler/src/ReactFiberCommitHostEffects.js
+159
-22
@@ -52,12 +52,25 @@ import {
52
} from './ReactFiberConfig';
53
import {captureCommitPhaseError} from './ReactFiberWorkLoop';
54
55
+import {runWithFiberInDEV} from './ReactCurrentFiber';
56
+
57
export function commitHostMount(finishedWork: Fiber) {
58
const type = finishedWork.type;
59
const props = finishedWork.memoizedProps;
60
const instance: Instance = finishedWork.stateNode;
61
try {
60
- commitMount(instance, type, props, finishedWork);
62
+ if (__DEV__) {
63
+ runWithFiberInDEV(
64
+ finishedWork,
65
+ commitMount,
66
+ instance,
67
+ type,
68
+ props,
69
+ finishedWork,
70
+ );
71
+ } else {
72
+ commitMount(instance, type, props, finishedWork);
73
+ }
74
} catch (error) {
75
captureCommitPhaseError(finishedWork, finishedWork.return, error);
76
}
@@ -69,13 +82,25 @@ export function commitHostUpdate(
82
oldProps: any,
83
) {
84
try {
72
- commitUpdate(
73
- finishedWork.stateNode,
74
- finishedWork.type,
75
- oldProps,
76
- newProps,
77
- finishedWork,
78
- );
85
+ if (__DEV__) {
86
+ runWithFiberInDEV(
87
+ finishedWork,
88
+ commitUpdate,
89
+ finishedWork.stateNode,
90
+ finishedWork.type,
91
+ oldProps,
92
+ newProps,
93
+ finishedWork,
94
+ );
95
+ } else {
96
+ commitUpdate(
97
+ finishedWork.stateNode,
98
+ finishedWork.type,
99
+ oldProps,
100
+ newProps,
101
+ finishedWork,
102
+ );
103
+ }
104
} catch (error) {
105
captureCommitPhaseError(finishedWork, finishedWork.return, error);
106
}
@@ -88,7 +113,17 @@ export function commitHostTextUpdate(
113
) {
114
const textInstance: TextInstance = finishedWork.stateNode;
115
try {
91
- commitTextUpdate(textInstance, oldText, newText);
116
+ if (__DEV__) {
117
+ runWithFiberInDEV(
118
+ finishedWork,
119
+ commitTextUpdate,
120
+ textInstance,
121
+ oldText,
122
+ newText,
123
+ );
124
+ } else {
125
+ commitTextUpdate(textInstance, oldText, newText);
126
+ }
127
} catch (error) {
128
captureCommitPhaseError(finishedWork, finishedWork.return, error);
129
}
@@ -97,7 +132,11 @@ export function commitHostTextUpdate(
132
export function commitHostResetTextContent(finishedWork: Fiber) {
133
const instance: Instance = finishedWork.stateNode;
134
try {
100
- resetTextContent(instance);
135
+ if (__DEV__) {
136
+ runWithFiberInDEV(finishedWork, resetTextContent, instance);
137
+ } else {
138
+ resetTextContent(instance);
139
+ }
140
} catch (error) {
141
captureCommitPhaseError(finishedWork, finishedWork.return, error);
142
}
@@ -107,9 +146,22 @@ export function commitShowHideHostInstance(node: Fiber, isHidden: boolean) {
146
try {
147
const instance = node.stateNode;
148
if (isHidden) {
110
- hideInstance(instance);
149
+ if (__DEV__) {
150
+ runWithFiberInDEV(node, hideInstance, instance);
151
+ } else {
152
+ hideInstance(instance);
153
+ }
154
} else {
112
- unhideInstance(node.stateNode, node.memoizedProps);
155
+ if (__DEV__) {
156
+ runWithFiberInDEV(
157
+ node,
158
+ unhideInstance,
159
+ node.stateNode,
160
+ node.memoizedProps,
161
+ );
162
+ } else {
163
+ unhideInstance(node.stateNode, node.memoizedProps);
164
+ }
165
}
166
} catch (error) {
167
captureCommitPhaseError(node, node.return, error);
@@ -120,9 +172,22 @@ export function commitShowHideHostTextInstance(node: Fiber, isHidden: boolean) {
172
try {
173
const instance = node.stateNode;
174
if (isHidden) {
123
- hideTextInstance(instance);
175
+ if (__DEV__) {
176
+ runWithFiberInDEV(node, hideTextInstance, instance);
177
+ } else {
178
+ hideTextInstance(instance);
179
+ }
180
} else {
125
- unhideTextInstance(instance, node.memoizedProps);
181
+ if (__DEV__) {
182
+ runWithFiberInDEV(
183
+ node,
184
+ unhideTextInstance,
185
+ instance,
186
+ node.memoizedProps,
187
+ );
188
+ } else {
189
+ unhideTextInstance(instance, node.memoizedProps);
190
+ }
191
}
192
} catch (error) {
193
captureCommitPhaseError(node, node.return, error);
@@ -332,7 +397,11 @@ function commitPlacement(finishedWork: Fiber): void {
397
398
export function commitHostPlacement(finishedWork: Fiber) {
399
try {
335
- commitPlacement(finishedWork);
400
+ if (__DEV__) {
401
+ runWithFiberInDEV(finishedWork, commitPlacement, finishedWork);
402
+ } else {
403
+ commitPlacement(finishedWork);
404
+ }
405
} catch (error) {
406
captureCommitPhaseError(finishedWork, finishedWork.return, error);
407
}
@@ -345,7 +414,16 @@ export function commitHostRemoveChildFromContainer(
414
hostInstance: Instance | TextInstance,
415
) {
416
try {
348
- removeChildFromContainer(parentContainer, hostInstance);
417
+ if (__DEV__) {
418
+ runWithFiberInDEV(
419
+ deletedFiber,
420
+ removeChildFromContainer,
421
+ parentContainer,
422
+ hostInstance,
423
+ );
424
+ } else {
425
+ removeChildFromContainer(parentContainer, hostInstance);
426
+ }
427
} catch (error) {
428
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
429
}
@@ -358,7 +436,16 @@ export function commitHostRemoveChild(
436
hostInstance: Instance | TextInstance,
437
) {
438
try {
361
- removeChild(parentInstance, hostInstance);
439
+ if (__DEV__) {
440
+ runWithFiberInDEV(
441
+ deletedFiber,
442
+ removeChild,
443
+ parentInstance,
444
+ hostInstance,
445
+ );
446
+ } else {
447
+ removeChild(parentInstance, hostInstance);
448
+ }
449
} catch (error) {
450
captureCommitPhaseError(deletedFiber, nearestMountedAncestor, error);
451
}
@@ -371,7 +458,16 @@ export function commitHostRootContainerChildren(
458
const containerInfo = root.containerInfo;
459
const pendingChildren = root.pendingChildren;
460
try {
374
- replaceContainerChildren(containerInfo, pendingChildren);
461
+ if (__DEV__) {
462
+ runWithFiberInDEV(
463
+ finishedWork,
464
+ replaceContainerChildren,
465
+ containerInfo,
466
+ pendingChildren,
467
+ );
468
+ } else {
469
+ replaceContainerChildren(containerInfo, pendingChildren);
470
+ }
471
} catch (error) {
472
captureCommitPhaseError(finishedWork, finishedWork.return, error);
473
}
@@ -388,7 +484,16 @@ export function commitHostPortalContainerChildren(
484
) {
485
const containerInfo = portal.containerInfo;
486
try {
391
- replaceContainerChildren(containerInfo, pendingChildren);
487
+ if (__DEV__) {
488
+ runWithFiberInDEV(
489
+ finishedWork,
490
+ replaceContainerChildren,
491
+ containerInfo,
492
+ pendingChildren,
493
+ );
494
+ } else {
495
+ replaceContainerChildren(containerInfo, pendingChildren);
496
+ }
497
} catch (error) {
498
captureCommitPhaseError(finishedWork, finishedWork.return, error);
499
}
@@ -399,7 +504,15 @@ export function commitHostHydratedContainer(
504
finishedWork: Fiber,
505
) {
506
try {
402
- commitHydratedContainer(root.containerInfo);
507
+ if (__DEV__) {
508
+ runWithFiberInDEV(
509
+ finishedWork,
510
+ commitHydratedContainer,
511
+ root.containerInfo,
512
+ );
513
+ } else {
514
+ commitHydratedContainer(root.containerInfo);
515
+ }
516
} catch (error) {
517
captureCommitPhaseError(finishedWork, finishedWork.return, error);
518
}
@@ -410,7 +523,15 @@ export function commitHostHydratedSuspense(
523
finishedWork: Fiber,
524
) {
525
try {
413
- commitHydratedSuspenseInstance(suspenseInstance);
526
+ if (__DEV__) {
527
+ runWithFiberInDEV(
528
+ finishedWork,
529
+ commitHydratedSuspenseInstance,
530
+ suspenseInstance,
531
+ );
532
+ } else {
533
+ commitHydratedSuspenseInstance(suspenseInstance);
534
+ }
535
} catch (error) {
536
captureCommitPhaseError(finishedWork, finishedWork.return, error);
537
}
@@ -423,7 +544,23 @@ export function commitHostSingleton(finishedWork: Fiber) {
544
try {
545
// This was a new mount, we need to clear and set initial properties
546
clearSingleton(singleton);
426
- acquireSingletonInstance(finishedWork.type, props, singleton, finishedWork);
547
+ if (__DEV__) {
548
+ runWithFiberInDEV(
549
+ finishedWork,
550
+ acquireSingletonInstance,
551
+ finishedWork.type,
552
+ props,
553
+ singleton,
554
+ finishedWork,
555
+ );
556
+ } else {
557
+ acquireSingletonInstance(
558
+ finishedWork.type,
559
+ props,
560
+ singleton,
561
+ finishedWork,
562
+ );
563
+ }
564
} catch (error) {
565
captureCommitPhaseError(finishedWork, finishedWork.return, error);
566
}
packages/react-reconciler/src/ReactFiberCommitWork.js
+40
-167
@@ -98,7 +98,6 @@ import {
98
FormReset,
99
Cloned,
100
} from './ReactFiberFlags';
101
-import {runWithFiberInDEV} from './ReactCurrentFiber';
101
import {
102
isCurrentUpdateNested,
103
getCommitTime,
@@ -289,11 +288,7 @@ function commitBeforeMutationEffects_begin() {
288
function commitBeforeMutationEffects_complete() {
289
while (nextEffect !== null) {
290
const fiber = nextEffect;
292
- if (__DEV__) {
293
- runWithFiberInDEV(fiber, commitBeforeMutationEffectsOnFiber, fiber);
294
- } else {
295
- commitBeforeMutationEffectsOnFiber(fiber);
296
- }
291
+ commitBeforeMutationEffectsOnFiber(fiber);
292
293
const sibling = fiber.sibling;
294
if (sibling !== null) {
@@ -1645,17 +1640,7 @@ export function commitMutationEffects(
1640
inProgressLanes = committedLanes;
1641
inProgressRoot = root;
1642
1648
- if (__DEV__) {
1649
- runWithFiberInDEV(
1650
- finishedWork,
1651
- commitMutationEffectsOnFiber,
1652
- finishedWork,
1653
- root,
1654
- committedLanes,
1655
- );
1656
- } else {
1657
- commitMutationEffectsOnFiber(finishedWork, root, committedLanes);
1658
- }
1643
+ commitMutationEffectsOnFiber(finishedWork, root, committedLanes);
1644
1645
inProgressLanes = null;
1646
inProgressRoot = null;
@@ -1682,17 +1667,7 @@ function recursivelyTraverseMutationEffects(
1667
) {
1668
let child = parentFiber.child;
1669
while (child !== null) {
1685
- if (__DEV__) {
1686
- runWithFiberInDEV(
1687
- child,
1688
- commitMutationEffectsOnFiber,
1689
- child,
1690
- root,
1691
- lanes,
1692
- );
1693
- } else {
1694
- commitMutationEffectsOnFiber(child, root, lanes);
1695
- }
1670
+ commitMutationEffectsOnFiber(child, root, lanes);
1671
child = child.sibling;
1672
}
1673
}
@@ -2235,18 +2210,7 @@ export function commitLayoutEffects(
2210
inProgressRoot = root;
2211
2212
const current = finishedWork.alternate;
2238
- if (__DEV__) {
2239
- runWithFiberInDEV(
2240
- finishedWork,
2241
- commitLayoutEffectOnFiber,
2242
- root,
2243
- current,
2244
- finishedWork,
2245
- committedLanes,
2246
- );
2247
- } else {
2248
- commitLayoutEffectOnFiber(root, current, finishedWork, committedLanes);
2249
- }
2213
+ commitLayoutEffectOnFiber(root, current, finishedWork, committedLanes);
2214
2215
inProgressLanes = null;
2216
inProgressRoot = null;
@@ -2261,18 +2225,7 @@ function recursivelyTraverseLayoutEffects(
2225
let child = parentFiber.child;
2226
while (child !== null) {
2227
const current = child.alternate;
2264
- if (__DEV__) {
2265
- runWithFiberInDEV(
2266
- child,
2267
- commitLayoutEffectOnFiber,
2268
- root,
2269
- current,
2270
- child,
2271
- lanes,
2272
- );
2273
- } else {
2274
- commitLayoutEffectOnFiber(root, current, child, lanes);
2275
- }
2228
+ commitLayoutEffectOnFiber(root, current, child, lanes);
2229
child = child.sibling;
2230
}
2231
}
@@ -2529,23 +2482,12 @@ function recursivelyTraverseReappearLayoutEffects(
2482
let child = parentFiber.child;
2483
while (child !== null) {
2484
const current = child.alternate;
2532
- if (__DEV__) {
2533
- runWithFiberInDEV(
2534
- child,
2535
- reappearLayoutEffects,
2536
- finishedRoot,
2537
- current,
2538
- child,
2539
- childShouldIncludeWorkInProgressEffects,
2540
- );
2541
- } else {
2542
- reappearLayoutEffects(
2543
- finishedRoot,
2544
- current,
2545
- child,
2546
- childShouldIncludeWorkInProgressEffects,
2547
- );
2548
- }
2485
+ reappearLayoutEffects(
2486
+ finishedRoot,
2487
+ current,
2488
+ child,
2489
+ childShouldIncludeWorkInProgressEffects,
2490
+ );
2491
child = child.sibling;
2492
}
2493
}
@@ -2696,23 +2638,12 @@ export function commitPassiveMountEffects(
2638
committedLanes: Lanes,
2639
committedTransitions: Array<Transition> | null,
2640
): void {
2699
- if (__DEV__) {
2700
- runWithFiberInDEV(
2701
- finishedWork,
2702
- commitPassiveMountOnFiber,
2703
- root,
2704
- finishedWork,
2705
- committedLanes,
2706
- committedTransitions,
2707
- );
2708
- } else {
2709
- commitPassiveMountOnFiber(
2710
- root,
2711
- finishedWork,
2712
- committedLanes,
2713
- committedTransitions,
2714
- );
2715
- }
2641
+ commitPassiveMountOnFiber(
2642
+ root,
2643
+ finishedWork,
2644
+ committedLanes,
2645
+ committedTransitions,
2646
+ );
2647
}
2648
2649
function recursivelyTraversePassiveMountEffects(
@@ -2724,23 +2655,12 @@ function recursivelyTraversePassiveMountEffects(
2655
if (parentFiber.subtreeFlags & PassiveMask) {
2656
let child = parentFiber.child;
2657
while (child !== null) {
2727
- if (__DEV__) {
2728
- runWithFiberInDEV(
2729
- child,
2730
- commitPassiveMountOnFiber,
2731
- root,
2732
- child,
2733
- committedLanes,
2734
- committedTransitions,
2735
- );
2736
- } else {
2737
- commitPassiveMountOnFiber(
2738
- root,
2739
- child,
2740
- committedLanes,
2741
- committedTransitions,
2742
- );
2743
- }
2658
+ commitPassiveMountOnFiber(
2659
+ root,
2660
+ child,
2661
+ committedLanes,
2662
+ committedTransitions,
2663
+ );
2664
child = child.sibling;
2665
}
2666
}
@@ -2982,25 +2902,13 @@ function recursivelyTraverseReconnectPassiveEffects(
2902
// TODO (Offscreen) Check: flags & (RefStatic | LayoutStatic)
2903
let child = parentFiber.child;
2904
while (child !== null) {
2985
- if (__DEV__) {
2986
- runWithFiberInDEV(
2987
- child,
2988
- reconnectPassiveEffects,
2989
- finishedRoot,
2990
- child,
2991
- committedLanes,
2992
- committedTransitions,
2993
- childShouldIncludeWorkInProgressEffects,
2994
- );
2995
- } else {
2996
- reconnectPassiveEffects(
2997
- finishedRoot,
2998
- child,
2999
- committedLanes,
3000
- committedTransitions,
3001
- childShouldIncludeWorkInProgressEffects,
3002
- );
3003
- }
2905
+ reconnectPassiveEffects(
2906
+ finishedRoot,
2907
+ child,
2908
+ committedLanes,
2909
+ committedTransitions,
2910
+ childShouldIncludeWorkInProgressEffects,
2911
+ );
2912
child = child.sibling;
2913
}
2914
}
@@ -3182,23 +3090,12 @@ function recursivelyTraverseAtomicPassiveEffects(
3090
if (parentFiber.subtreeFlags & PassiveMask) {
3091
let child = parentFiber.child;
3092
while (child !== null) {
3185
- if (__DEV__) {
3186
- runWithFiberInDEV(
3187
- child,
3188
- commitAtomicPassiveEffects,
3189
- finishedRoot,
3190
- child,
3191
- committedLanes,
3192
- committedTransitions,
3193
- );
3194
- } else {
3195
- commitAtomicPassiveEffects(
3196
- finishedRoot,
3197
- child,
3198
- committedLanes,
3199
- committedTransitions,
3200
- );
3201
- }
3093
+ commitAtomicPassiveEffects(
3094
+ finishedRoot,
3095
+ child,
3096
+ committedLanes,
3097
+ committedTransitions,
3098
+ );
3099
child = child.sibling;
3100
}
3101
}
@@ -3257,11 +3154,7 @@ function commitAtomicPassiveEffects(
3154
}
3155
3156
export function commitPassiveUnmountEffects(finishedWork: Fiber): void {
3260
- if (__DEV__) {
3261
- runWithFiberInDEV(finishedWork, commitPassiveUnmountOnFiber, finishedWork);
3262
- } else {
3263
- commitPassiveUnmountOnFiber(finishedWork);
3264
- }
3157
+ commitPassiveUnmountOnFiber(finishedWork);
3158
}
3159
3160
// If we're inside a brand new tree, or a tree that was already visible, then we
@@ -3412,11 +3305,7 @@ function recursivelyTraversePassiveUnmountEffects(parentFiber: Fiber): void {
3305
if (parentFiber.subtreeFlags & PassiveMask) {
3306
let child = parentFiber.child;
3307
while (child !== null) {
3415
- if (__DEV__) {
3416
- runWithFiberInDEV(child, commitPassiveUnmountOnFiber, child);
3417
- } else {
3418
- commitPassiveUnmountOnFiber(child);
3419
- }
3308
+ commitPassiveUnmountOnFiber(child);
3309
child = child.sibling;
3310
}
3311
}
@@ -3493,11 +3382,7 @@ function recursivelyTraverseDisconnectPassiveEffects(parentFiber: Fiber): void {
3382
// TODO: Check PassiveStatic flag
3383
let child = parentFiber.child;
3384
while (child !== null) {
3496
- if (__DEV__) {
3497
- runWithFiberInDEV(child, disconnectPassiveEffect, child);
3498
- } else {
3499
- disconnectPassiveEffect(child);
3500
- }
3385
+ disconnectPassiveEffect(child);
3386
child = child.sibling;
3387
}
3388
}
@@ -3544,19 +3429,7 @@ function commitPassiveUnmountEffectsInsideOfDeletedTree_begin(
3429
3430
// Deletion effects fire in parent -> child order
3431
// TODO: Check if fiber has a PassiveStatic flag
3547
- if (__DEV__) {
3548
- runWithFiberInDEV(
3549
- fiber,
3550
- commitPassiveUnmountInsideDeletedTreeOnFiber,
3551
- fiber,
3552
- nearestMountedAncestor,
3553
- );
3554
- } else {
3555
- commitPassiveUnmountInsideDeletedTreeOnFiber(
3556
- fiber,
3557
- nearestMountedAncestor,
3558
- );
3559
- }
3432
+ commitPassiveUnmountInsideDeletedTreeOnFiber(fiber, nearestMountedAncestor);
3433
3434
const child = fiber.child;
3435
// TODO: Only traverse subtree if it has a PassiveStatic flag.
packages/react-reconciler/src/__tests__/ReactSuspenseCallback-test.js
+4
-3
@@ -57,9 +57,10 @@ describe('ReactSuspense', () => {
57
);
58
59
ReactNoop.render(elementBadType);
60
- await expect(async () => await waitForAll([])).toErrorDev([
61
- 'Unexpected type for suspenseCallback.',
62
- ]);
60
+ await expect(async () => await waitForAll([])).toErrorDev(
61
+ ['Unexpected type for suspenseCallback.'],
62
+ {withoutStack: true},
63
+ );
64
65
const elementMissingCallback = (
66
<React.Suspense fallback={'Waiting'}>