MCPcopy
hub / github.com/facebook/react / safelyDetachRef

Function safelyDetachRef

packages/react-reconciler/src/ReactFiberCommitEffects.js:841–907  ·  view source on GitHub ↗
(
  current: Fiber,
  nearestMountedAncestor: Fiber | null,
)

Source from the content-addressed store, hash-verified

839}
840
841export function safelyDetachRef(
842 current: Fiber,
843 nearestMountedAncestor: Fiber | null,
844) {
845 const ref = current.ref;
846 const refCleanup = current.refCleanup;
847
848 if (ref !== null) {
849 if (typeof refCleanup === 'function') {
850 try {
851 if (shouldProfile(current)) {
852 try {
853 startEffectTimer();
854 if (__DEV__) {
855 runWithFiberInDEV(current, refCleanup);
856 } else {
857 refCleanup();
858 }
859 } finally {
860 recordEffectDuration(current);
861 }
862 } else {
863 if (__DEV__) {
864 runWithFiberInDEV(current, refCleanup);
865 } else {
866 refCleanup();
867 }
868 }
869 } catch (error) {
870 captureCommitPhaseError(current, nearestMountedAncestor, error);
871 } finally {
872 // `refCleanup` has been called. Nullify all references to it to prevent double invocation.
873 current.refCleanup = null;
874 const finishedWork = current.alternate;
875 if (finishedWork != null) {
876 finishedWork.refCleanup = null;
877 }
878 }
879 } else if (typeof ref === 'function') {
880 try {
881 if (shouldProfile(current)) {
882 try {
883 startEffectTimer();
884 if (__DEV__) {
885 (runWithFiberInDEV(current, ref, null): void);
886 } else {
887 ref(null);
888 }
889 } finally {
890 recordEffectDuration(current);
891 }
892 } else {
893 if (__DEV__) {
894 (runWithFiberInDEV(current, ref, null): void);
895 } else {
896 ref(null);
897 }
898 }

Callers 3

disappearLayoutEffectsFunction · 0.90

Calls 6

startEffectTimerFunction · 0.90
runWithFiberInDEVFunction · 0.90
recordEffectDurationFunction · 0.90
captureCommitPhaseErrorFunction · 0.90
shouldProfileFunction · 0.85
refFunction · 0.85

Tested by

no test coverage detected