213
} from './ReactFiberTracingMarkerComponent';
214
import {scheduleUpdateOnFiber} from './ReactFiberWorkLoop';
215
import {enqueueConcurrentRenderForLane} from './ReactFiberConcurrentUpdates';
216
+import {
217
+ callComponentDidMountInDEV,
218
+ callComponentDidUpdateInDEV,
219
+ callComponentWillUnmountInDEV,
220
+ callCreateInDEV,
221
+ callDestroyInDEV,
222
+} from './ReactFiberCallUserSpace';
223
224
let didWarnAboutUndefinedSnapshotBeforeUpdate: Set<mixed> | null = null;
225
if (__DEV__) {
251
);
252
}
253
247
-function callComponentWillUnmountWithTimer(current: Fiber, instance: any) {
254
+// Capture errors so they don't interrupt unmounting.
255
+function safelyCallComponentWillUnmount(
256
+ current: Fiber,
257
+ nearestMountedAncestor: Fiber | null,
258
+ instance: any,
259
+) {
260
instance.props = resolveClassComponentProps(
261
current.type,
262
current.memoizedProps,
264
);
265
instance.state = current.memoizedState;
266
if (shouldProfile(current)) {
255
- try {
256
- startLayoutEffectTimer();
257
- instance.componentWillUnmount();
258
- } finally {
259
- recordLayoutEffectDuration(current);
267
+ startLayoutEffectTimer();
268
+ if (__DEV__) {
269
+ callComponentWillUnmountInDEV(current, nearestMountedAncestor, instance);
270
+ } else {
271
+ try {
272
+ instance.componentWillUnmount();
273
+ } catch (error) {
274
+ captureCommitPhaseError(current, nearestMountedAncestor, error);
275
+ }
276
}
277
+ recordLayoutEffectDuration(current);
278
} else {
262
- instance.componentWillUnmount();
263
- }
264
-}
265
-
266
-// Capture errors so they don't interrupt unmounting.
267
-function safelyCallComponentWillUnmount(
268
- current: Fiber,
269
- nearestMountedAncestor: Fiber | null,
270
- instance: any,
271
-) {
272
- try {
273
- callComponentWillUnmountWithTimer(current, instance);
274
- } catch (error) {
275
- captureCommitPhaseError(current, nearestMountedAncestor, error);
279
+ if (__DEV__) {
280
+ callComponentWillUnmountInDEV(current, nearestMountedAncestor, instance);
281
+ } else {
282
+ try {
283
+ instance.componentWillUnmount();
284
+ } catch (error) {
285
+ captureCommitPhaseError(current, nearestMountedAncestor, error);
286
+ }
287
+ }
288
}
289
}
290
351
nearestMountedAncestor: Fiber | null,
352
destroy: () => void,
353
) {
342
- try {
343
- destroy();
344
- } catch (error) {
345
- captureCommitPhaseError(current, nearestMountedAncestor, error);
354
+ if (__DEV__) {
355
+ callDestroyInDEV(current, nearestMountedAncestor, destroy);
356
+ } else {
357
+ try {
358
+ destroy();
359
+ } catch (error) {
360
+ captureCommitPhaseError(current, nearestMountedAncestor, error);
361
+ }
362
}
363
}
364
642
}
643
644
// Mount
629
- const create = effect.create;
645
+ let destroy;
646
if (__DEV__) {
647
if ((flags & HookInsertion) !== NoHookEffect) {
648
setIsRunningInsertionEffect(true);
649
}
634
- }
635
- const inst = effect.inst;
636
- const destroy = create();
637
- inst.destroy = destroy;
638
- if (__DEV__) {
650
+ destroy = callCreateInDEV(effect);
651
if ((flags & HookInsertion) !== NoHookEffect) {
652
setIsRunningInsertionEffect(false);
653
}
654
+ } else {
655
+ const create = effect.create;
656
+ const inst = effect.inst;
657
+ destroy = create();
658
+ inst.destroy = destroy;
659
}
660
661
if (enableSchedulingProfiler) {
843
}
844
}
845
if (shouldProfile(finishedWork)) {
829
- try {
830
- startLayoutEffectTimer();
831
- instance.componentDidMount();
832
- } catch (error) {
833
- captureCommitPhaseError(finishedWork, finishedWork.return, error);
846
+ startLayoutEffectTimer();
847
+ if (__DEV__) {
848
+ callComponentDidMountInDEV(finishedWork, instance);
849
+ } else {
850
+ try {
851
+ instance.componentDidMount();
852
+ } catch (error) {
853
+ captureCommitPhaseError(finishedWork, finishedWork.return, error);
854
+ }
855
}
856
recordLayoutEffectDuration(finishedWork);
857
} else {
837
- try {
838
- instance.componentDidMount();
839
- } catch (error) {
840
- captureCommitPhaseError(finishedWork, finishedWork.return, error);
858
+ if (__DEV__) {
859
+ callComponentDidMountInDEV(finishedWork, instance);
860
+ } else {
861
+ try {
862
+ instance.componentDidMount();
863
+ } catch (error) {
864
+ captureCommitPhaseError(finishedWork, finishedWork.return, error);
865
+ }
866
}
867
}
868
} else {
904
}
905
}
906
if (shouldProfile(finishedWork)) {
882
- try {
883
- startLayoutEffectTimer();
884
- instance.componentDidUpdate(
907
+ startLayoutEffectTimer();
908
+ if (__DEV__) {
909
+ callComponentDidUpdateInDEV(
910
+ finishedWork,
911
+ instance,
912
prevProps,
913
prevState,
914
instance.__reactInternalSnapshotBeforeUpdate,
915
);
889
- } catch (error) {
890
- captureCommitPhaseError(finishedWork, finishedWork.return, error);
916
+ } else {
917
+ try {
918
+ instance.componentDidUpdate(
919
+ prevProps,
920
+ prevState,
921
+ instance.__reactInternalSnapshotBeforeUpdate,
922
+ );
923
+ } catch (error) {
924
+ captureCommitPhaseError(finishedWork, finishedWork.return, error);
925
+ }
926
}
927
recordLayoutEffectDuration(finishedWork);
928
} else {
894
- try {
895
- instance.componentDidUpdate(
929
+ if (__DEV__) {
930
+ callComponentDidUpdateInDEV(
931
+ finishedWork,
932
+ instance,
933
prevProps,
934
prevState,
935
instance.__reactInternalSnapshotBeforeUpdate,
936
);
900
- } catch (error) {
901
- captureCommitPhaseError(finishedWork, finishedWork.return, error);
937
+ } else {
938
+ try {
939
+ instance.componentDidUpdate(
940
+ prevProps,
941
+ prevState,
942
+ instance.__reactInternalSnapshotBeforeUpdate,
943
+ );
944
+ } catch (error) {
945
+ captureCommitPhaseError(finishedWork, finishedWork.return, error);
946
+ }
947
}
948
}
949
}