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

Function flushSync

packages/react-noop-renderer/src/createReactNoop.js:1116–1145  ·  view source on GitHub ↗
(fn: () => R)

Source from the content-addressed store, hash-verified

1114 }
1115
1116 function flushSync<R>(fn: () => R): R {
1117 if (__DEV__) {
1118 if (NoopRenderer.isAlreadyRendering()) {
1119 console.error(
1120 'flushSync was called from inside a lifecycle method. React cannot ' +
1121 'flush when React is already rendering. Consider moving this call to ' +
1122 'a scheduler task or micro task.',
1123 );
1124 }
1125 }
1126 if (disableLegacyMode) {
1127 const previousTransition = ReactSharedInternals.T;
1128 const preivousEventPriority = currentEventPriority;
1129 try {
1130 ReactSharedInternals.T = null;
1131 currentEventPriority = DiscreteEventPriority;
1132 if (fn) {
1133 return fn();
1134 } else {
1135 return undefined;
1136 }
1137 } finally {
1138 ReactSharedInternals.T = previousTransition;
1139 currentEventPriority = preivousEventPriority;
1140 NoopRenderer.flushSyncWork();
1141 }
1142 } else {
1143 return NoopRenderer.flushSyncFromReconciler(fn);
1144 }
1145 }
1146
1147 function onRecoverableError(error) {
1148 // TODO: Turn this on once tests are fixed

Callers 4

safeUnmountFunction · 0.85
performFullCleanupFunction · 0.85
toggleHighlightFunction · 0.85

Calls 2

errorMethod · 0.65
fnFunction · 0.50

Tested by

no test coverage detected