GeezerVison is showing github.com — Revert "Fix: flushSync changes priority inside effect (#21122)" · react/react@e7e0a90
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/react-reconciler/src
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js +11-11Lines changed: 11 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1142,6 +1142,16 @@ export function unbatchedUpdates<A, R>(fn: (a: A) => R, a: A): R { |
1142 | 1142 |
|
1143 | 1143 | export function flushSync<A, R>(fn: A => R, a: A): R { |
1144 | 1144 | const prevExecutionContext = executionContext; |
| 1145 | + if ((prevExecutionContext & (RenderContext | CommitContext)) !== NoContext) { |
| 1146 | + if (__DEV__) { |
| 1147 | + console.error( |
| 1148 | + 'flushSync was called from inside a lifecycle method. React cannot ' + |
| 1149 | + 'flush when React is already rendering. Consider moving this call to ' + |
| 1150 | + 'a scheduler task or micro task.', |
| 1151 | + ); |
| 1152 | + } |
| 1153 | + return fn(a); |
| 1154 | + } |
1145 | 1155 | executionContext |= BatchedContext; |
1146 | 1156 |
|
1147 | 1157 | const previousPriority = getCurrentUpdatePriority(); |
@@ -1158,17 +1168,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R { |
1158 | 1168 | // Flush the immediate callbacks that were scheduled during this batch. |
1159 | 1169 | // Note that this will happen even if batchedUpdates is higher up |
1160 | 1170 | // the stack. |
1161 | | - if ((executionContext & (RenderContext | CommitContext)) === NoContext) { |
1162 | | - flushSyncCallbacks(); |
1163 | | - } else { |
1164 | | - if (__DEV__) { |
1165 | | - console.error( |
1166 | | - 'flushSync was called from inside a lifecycle method. React cannot ' + |
1167 | | - 'flush when React is already rendering. Consider moving this call to ' + |
1168 | | - 'a scheduler task or micro task.', |
1169 | | - ); |
1170 | | - } |
1171 | | - } |
| 1171 | + flushSyncCallbacks(); |
1172 | 1172 | } |
1173 | 1173 | } |
1174 | 1174 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.old.js +11-11Lines changed: 11 additions & 11 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1142,6 +1142,16 @@ export function unbatchedUpdates<A, R>(fn: (a: A) => R, a: A): R { |
1142 | 1142 |
|
1143 | 1143 | export function flushSync<A, R>(fn: A => R, a: A): R { |
1144 | 1144 | const prevExecutionContext = executionContext; |
| 1145 | + if ((prevExecutionContext & (RenderContext | CommitContext)) !== NoContext) { |
| 1146 | + if (__DEV__) { |
| 1147 | + console.error( |
| 1148 | + 'flushSync was called from inside a lifecycle method. React cannot ' + |
| 1149 | + 'flush when React is already rendering. Consider moving this call to ' + |
| 1150 | + 'a scheduler task or micro task.', |
| 1151 | + ); |
| 1152 | + } |
| 1153 | + return fn(a); |
| 1154 | + } |
1145 | 1155 | executionContext |= BatchedContext; |
1146 | 1156 |
|
1147 | 1157 | const previousPriority = getCurrentUpdatePriority(); |
@@ -1158,17 +1168,7 @@ export function flushSync<A, R>(fn: A => R, a: A): R { |
1158 | 1168 | // Flush the immediate callbacks that were scheduled during this batch. |
1159 | 1169 | // Note that this will happen even if batchedUpdates is higher up |
1160 | 1170 | // the stack. |
1161 | | - if ((executionContext & (RenderContext | CommitContext)) === NoContext) { |
1162 | | - flushSyncCallbacks(); |
1163 | | - } else { |
1164 | | - if (__DEV__) { |
1165 | | - console.error( |
1166 | | - 'flushSync was called from inside a lifecycle method. React cannot ' + |
1167 | | - 'flush when React is already rendering. Consider moving this call to ' + |
1168 | | - 'a scheduler task or micro task.', |
1169 | | - ); |
1170 | | - } |
1171 | | - } |
| 1171 | + flushSyncCallbacks(); |
1172 | 1172 | } |
1173 | 1173 | } |
1174 | 1174 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactFlushSync-test.js -64Lines changed: 0 additions & 64 deletions