GeezerVison is showing github.com — Revert "Support nesting of startTransition and flushSync (alt) (#21149)" · react/react@207d4c3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/events/ReactDOMEventListener.js -6Lines changed: 0 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,9 +49,6 @@ import { | 49 | 49 | getCurrentUpdatePriority, | 50 | 50 | setCurrentUpdatePriority, | 51 | 51 | } from 'react-reconciler/src/ReactEventPriorities'; | 52 | | -import ReactSharedInternals from 'shared/ReactSharedInternals'; | 53 | | - | 54 | | -const {ReactCurrentBatchConfig} = ReactSharedInternals; | 55 | 52 |
| 56 | 53 | // TODO: can we stop exporting these? | 57 | 54 | export let _enabled = true; | @@ -128,14 +125,11 @@ function dispatchContinuousEvent( | 128 | 125 | nativeEvent, | 129 | 126 | ) { | 130 | 127 | const previousPriority = getCurrentUpdatePriority(); | 131 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 132 | | - ReactCurrentBatchConfig.transition = 0; | 133 | 128 | try { | 134 | 129 | setCurrentUpdatePriority(ContinuousEventPriority); | 135 | 130 | dispatchEvent(domEventName, eventSystemFlags, container, nativeEvent); | 136 | 131 | } finally { | 137 | 132 | setCurrentUpdatePriority(previousPriority); | 138 | | - ReactCurrentBatchConfig.transition = prevTransition; | 139 | 133 | } | 140 | 134 | } | 141 | 135 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.new.js -22Lines changed: 0 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,7 +245,6 @@ const ceil = Math.ceil; | 245 | 245 | const { | 246 | 246 | ReactCurrentDispatcher, | 247 | 247 | ReactCurrentOwner, | 248 | | - ReactCurrentBatchConfig, | 249 | 248 | IsSomeRendererActing, | 250 | 249 | } = ReactSharedInternals; | 251 | 250 |
| @@ -1063,14 +1062,11 @@ export function flushDiscreteUpdates() { | 1063 | 1062 |
| 1064 | 1063 | export function deferredUpdates<A>(fn: () => A): A { | 1065 | 1064 | const previousPriority = getCurrentUpdatePriority(); | 1066 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1067 | 1065 | try { | 1068 | | - ReactCurrentBatchConfig.transition = 0; | 1069 | 1066 | setCurrentUpdatePriority(DefaultEventPriority); | 1070 | 1067 | return fn(); | 1071 | 1068 | } finally { | 1072 | 1069 | setCurrentUpdatePriority(previousPriority); | 1073 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1074 | 1070 | } | 1075 | 1071 | } | 1076 | 1072 |
| @@ -1114,14 +1110,11 @@ export function discreteUpdates<A, B, C, D, R>( | 1114 | 1110 | d: D, | 1115 | 1111 | ): R { | 1116 | 1112 | const previousPriority = getCurrentUpdatePriority(); | 1117 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1118 | 1113 | try { | 1119 | | - ReactCurrentBatchConfig.transition = 0; | 1120 | 1114 | setCurrentUpdatePriority(DiscreteEventPriority); | 1121 | 1115 | return fn(a, b, c, d); | 1122 | 1116 | } finally { | 1123 | 1117 | setCurrentUpdatePriority(previousPriority); | 1124 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1125 | 1118 | if (executionContext === NoContext) { | 1126 | 1119 | resetRenderTimer(); | 1127 | 1120 | } | @@ -1151,10 +1144,8 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1151 | 1144 | const prevExecutionContext = executionContext; | 1152 | 1145 | executionContext |= BatchedContext; | 1153 | 1146 |
| 1154 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1155 | 1147 | const previousPriority = getCurrentUpdatePriority(); | 1156 | 1148 | try { | 1157 | | - ReactCurrentBatchConfig.transition = 0; | 1158 | 1149 | setCurrentUpdatePriority(DiscreteEventPriority); | 1159 | 1150 | if (fn) { | 1160 | 1151 | return fn(a); | @@ -1163,7 +1154,6 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1163 | 1154 | } | 1164 | 1155 | } finally { | 1165 | 1156 | setCurrentUpdatePriority(previousPriority); | 1166 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1167 | 1157 | executionContext = prevExecutionContext; | 1168 | 1158 | // Flush the immediate callbacks that were scheduled during this batch. | 1169 | 1159 | // Note that this will happen even if batchedUpdates is higher up | @@ -1185,15 +1175,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1185 | 1175 | export function flushControlled(fn: () => mixed): void { | 1186 | 1176 | const prevExecutionContext = executionContext; | 1187 | 1177 | executionContext |= BatchedContext; | 1188 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1189 | 1178 | const previousPriority = getCurrentUpdatePriority(); | 1190 | 1179 | try { | 1191 | | - ReactCurrentBatchConfig.transition = 0; | 1192 | 1180 | setCurrentUpdatePriority(DiscreteEventPriority); | 1193 | 1181 | fn(); | 1194 | 1182 | } finally { | 1195 | 1183 | setCurrentUpdatePriority(previousPriority); | 1196 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1197 | 1184 |
| 1198 | 1185 | executionContext = prevExecutionContext; | 1199 | 1186 | if (executionContext === NoContext) { | @@ -1688,13 +1675,10 @@ function commitRoot(root) { | 1688 | 1675 | // TODO: This no longer makes any sense. We already wrap the mutation and | 1689 | 1676 | // layout phases. Should be able to remove. | 1690 | 1677 | const previousUpdateLanePriority = getCurrentUpdatePriority(); | 1691 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1692 | 1678 | try { | 1693 | | - ReactCurrentBatchConfig.transition = 0; | 1694 | 1679 | setCurrentUpdatePriority(DiscreteEventPriority); | 1695 | 1680 | commitRootImpl(root, previousUpdateLanePriority); | 1696 | 1681 | } finally { | 1697 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1698 | 1682 | setCurrentUpdatePriority(previousUpdateLanePriority); | 1699 | 1683 | } | 1700 | 1684 |
| @@ -1816,8 +1800,6 @@ function commitRootImpl(root, renderPriorityLevel) { | 1816 | 1800 | NoFlags; | 1817 | 1801 |
| 1818 | 1802 | if (subtreeHasEffects || rootHasEffect) { | 1819 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1820 | | - ReactCurrentBatchConfig.transition = 0; | 1821 | 1803 | const previousPriority = getCurrentUpdatePriority(); | 1822 | 1804 | setCurrentUpdatePriority(DiscreteEventPriority); | 1823 | 1805 |
| @@ -1899,7 +1881,6 @@ function commitRootImpl(root, renderPriorityLevel) { | 1899 | 1881 |
| 1900 | 1882 | // Reset the priority to the previous non-sync value. | 1901 | 1883 | setCurrentUpdatePriority(previousPriority); | 1902 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1903 | 1884 | } else { | 1904 | 1885 | // No effects. | 1905 | 1886 | root.current = finishedWork; | @@ -2036,15 +2017,12 @@ export function flushPassiveEffects(): boolean { | 2036 | 2017 | if (rootWithPendingPassiveEffects !== null) { | 2037 | 2018 | const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes); | 2038 | 2019 | const priority = lowerEventPriority(DefaultEventPriority, renderPriority); | 2039 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 2040 | 2020 | const previousPriority = getCurrentUpdatePriority(); | 2041 | 2021 | try { | 2042 | | - ReactCurrentBatchConfig.transition = 0; | 2043 | 2022 | setCurrentUpdatePriority(priority); | 2044 | 2023 | return flushPassiveEffectsImpl(); | 2045 | 2024 | } finally { | 2046 | 2025 | setCurrentUpdatePriority(previousPriority); | 2047 | | - ReactCurrentBatchConfig.transition = prevTransition; | 2048 | 2026 | } | 2049 | 2027 | } | 2050 | 2028 | return false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberWorkLoop.old.js -22Lines changed: 0 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,7 +245,6 @@ const ceil = Math.ceil; | 245 | 245 | const { | 246 | 246 | ReactCurrentDispatcher, | 247 | 247 | ReactCurrentOwner, | 248 | | - ReactCurrentBatchConfig, | 249 | 248 | IsSomeRendererActing, | 250 | 249 | } = ReactSharedInternals; | 251 | 250 |
| @@ -1063,14 +1062,11 @@ export function flushDiscreteUpdates() { | 1063 | 1062 |
| 1064 | 1063 | export function deferredUpdates<A>(fn: () => A): A { | 1065 | 1064 | const previousPriority = getCurrentUpdatePriority(); | 1066 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1067 | 1065 | try { | 1068 | | - ReactCurrentBatchConfig.transition = 0; | 1069 | 1066 | setCurrentUpdatePriority(DefaultEventPriority); | 1070 | 1067 | return fn(); | 1071 | 1068 | } finally { | 1072 | 1069 | setCurrentUpdatePriority(previousPriority); | 1073 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1074 | 1070 | } | 1075 | 1071 | } | 1076 | 1072 |
| @@ -1114,14 +1110,11 @@ export function discreteUpdates<A, B, C, D, R>( | 1114 | 1110 | d: D, | 1115 | 1111 | ): R { | 1116 | 1112 | const previousPriority = getCurrentUpdatePriority(); | 1117 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1118 | 1113 | try { | 1119 | | - ReactCurrentBatchConfig.transition = 0; | 1120 | 1114 | setCurrentUpdatePriority(DiscreteEventPriority); | 1121 | 1115 | return fn(a, b, c, d); | 1122 | 1116 | } finally { | 1123 | 1117 | setCurrentUpdatePriority(previousPriority); | 1124 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1125 | 1118 | if (executionContext === NoContext) { | 1126 | 1119 | resetRenderTimer(); | 1127 | 1120 | } | @@ -1151,10 +1144,8 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1151 | 1144 | const prevExecutionContext = executionContext; | 1152 | 1145 | executionContext |= BatchedContext; | 1153 | 1146 |
| 1154 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1155 | 1147 | const previousPriority = getCurrentUpdatePriority(); | 1156 | 1148 | try { | 1157 | | - ReactCurrentBatchConfig.transition = 0; | 1158 | 1149 | setCurrentUpdatePriority(DiscreteEventPriority); | 1159 | 1150 | if (fn) { | 1160 | 1151 | return fn(a); | @@ -1163,7 +1154,6 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1163 | 1154 | } | 1164 | 1155 | } finally { | 1165 | 1156 | setCurrentUpdatePriority(previousPriority); | 1166 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1167 | 1157 | executionContext = prevExecutionContext; | 1168 | 1158 | // Flush the immediate callbacks that were scheduled during this batch. | 1169 | 1159 | // Note that this will happen even if batchedUpdates is higher up | @@ -1185,15 +1175,12 @@ export function flushSync<A, R>(fn: A => R, a: A): R { | 1185 | 1175 | export function flushControlled(fn: () => mixed): void { | 1186 | 1176 | const prevExecutionContext = executionContext; | 1187 | 1177 | executionContext |= BatchedContext; | 1188 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1189 | 1178 | const previousPriority = getCurrentUpdatePriority(); | 1190 | 1179 | try { | 1191 | | - ReactCurrentBatchConfig.transition = 0; | 1192 | 1180 | setCurrentUpdatePriority(DiscreteEventPriority); | 1193 | 1181 | fn(); | 1194 | 1182 | } finally { | 1195 | 1183 | setCurrentUpdatePriority(previousPriority); | 1196 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1197 | 1184 |
| 1198 | 1185 | executionContext = prevExecutionContext; | 1199 | 1186 | if (executionContext === NoContext) { | @@ -1688,13 +1675,10 @@ function commitRoot(root) { | 1688 | 1675 | // TODO: This no longer makes any sense. We already wrap the mutation and | 1689 | 1676 | // layout phases. Should be able to remove. | 1690 | 1677 | const previousUpdateLanePriority = getCurrentUpdatePriority(); | 1691 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1692 | 1678 | try { | 1693 | | - ReactCurrentBatchConfig.transition = 0; | 1694 | 1679 | setCurrentUpdatePriority(DiscreteEventPriority); | 1695 | 1680 | commitRootImpl(root, previousUpdateLanePriority); | 1696 | 1681 | } finally { | 1697 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1698 | 1682 | setCurrentUpdatePriority(previousUpdateLanePriority); | 1699 | 1683 | } | 1700 | 1684 |
| @@ -1816,8 +1800,6 @@ function commitRootImpl(root, renderPriorityLevel) { | 1816 | 1800 | NoFlags; | 1817 | 1801 |
| 1818 | 1802 | if (subtreeHasEffects || rootHasEffect) { | 1819 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 1820 | | - ReactCurrentBatchConfig.transition = 0; | 1821 | 1803 | const previousPriority = getCurrentUpdatePriority(); | 1822 | 1804 | setCurrentUpdatePriority(DiscreteEventPriority); | 1823 | 1805 |
| @@ -1899,7 +1881,6 @@ function commitRootImpl(root, renderPriorityLevel) { | 1899 | 1881 |
| 1900 | 1882 | // Reset the priority to the previous non-sync value. | 1901 | 1883 | setCurrentUpdatePriority(previousPriority); | 1902 | | - ReactCurrentBatchConfig.transition = prevTransition; | 1903 | 1884 | } else { | 1904 | 1885 | // No effects. | 1905 | 1886 | root.current = finishedWork; | @@ -2036,15 +2017,12 @@ export function flushPassiveEffects(): boolean { | 2036 | 2017 | if (rootWithPendingPassiveEffects !== null) { | 2037 | 2018 | const renderPriority = lanesToEventPriority(pendingPassiveEffectsLanes); | 2038 | 2019 | const priority = lowerEventPriority(DefaultEventPriority, renderPriority); | 2039 | | - const prevTransition = ReactCurrentBatchConfig.transition; | 2040 | 2020 | const previousPriority = getCurrentUpdatePriority(); | 2041 | 2021 | try { | 2042 | | - ReactCurrentBatchConfig.transition = 0; | 2043 | 2022 | setCurrentUpdatePriority(priority); | 2044 | 2023 | return flushPassiveEffectsImpl(); | 2045 | 2024 | } finally { | 2046 | 2025 | setCurrentUpdatePriority(previousPriority); | 2047 | | - ReactCurrentBatchConfig.transition = prevTransition; | 2048 | 2026 | } | 2049 | 2027 | } | 2050 | 2028 | return false; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactFlushSync-test.js -43Lines changed: 0 additions & 43 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,6 @@ let ReactNoop; | 3 | 3 | let Scheduler; | 4 | 4 | let useState; | 5 | 5 | let useEffect; | 6 | | -let startTransition; | 7 | 6 |
| 8 | 7 | describe('ReactFlushSync', () => { | 9 | 8 | beforeEach(() => { | @@ -14,7 +13,6 @@ describe('ReactFlushSync', () => { | 14 | 13 | Scheduler = require('scheduler'); | 15 | 14 | useState = React.useState; | 16 | 15 | useEffect = React.useEffect; | 17 | | - startTransition = React.unstable_startTransition; | 18 | 16 | }); | 19 | 17 |
| 20 | 18 | function Text({text}) { | @@ -64,47 +62,6 @@ describe('ReactFlushSync', () => { | 64 | 62 | expect(root).toMatchRenderedOutput('1, 1'); | 65 | 63 | }); | 66 | 64 |
| 67 | | - // @gate experimental | 68 | | - test('nested with startTransition', async () => { | 69 | | - let setSyncState; | 70 | | - let setState; | 71 | | - function App() { | 72 | | - const [syncState, _setSyncState] = useState(0); | 73 | | - const [state, _setState] = useState(0); | 74 | | - setSyncState = _setSyncState; | 75 | | - setState = _setState; | 76 | | - return <Text text={`${syncState}, ${state}`} />; | 77 | | - } | 78 | | - | 79 | | - const root = ReactNoop.createRoot(); | 80 | | - await ReactNoop.act(async () => { | 81 | | - root.render(<App />); | 82 | | - }); | 83 | | - expect(Scheduler).toHaveYielded(['0, 0']); | 84 | | - expect(root).toMatchRenderedOutput('0, 0'); | 85 | | - | 86 | | - await ReactNoop.act(async () => { | 87 | | - ReactNoop.flushSync(() => { | 88 | | - startTransition(() => { | 89 | | - // This should be async even though flushSync is on the stack, because | 90 | | - // startTransition is closer. | 91 | | - setState(1); | 92 | | - ReactNoop.flushSync(() => { | 93 | | - // This should be async even though startTransition is on the stack, | 94 | | - // because flushSync is closer. | 95 | | - setSyncState(1); | 96 | | - }); | 97 | | - }); | 98 | | - }); | 99 | | - // Only the sync update should have flushed | 100 | | - expect(Scheduler).toHaveYielded(['1, 0']); | 101 | | - expect(root).toMatchRenderedOutput('1, 0'); | 102 | | - }); | 103 | | - // Now the async update has flushed, too. | 104 | | - expect(Scheduler).toHaveYielded(['1, 1']); | 105 | | - expect(root).toMatchRenderedOutput('1, 1'); | 106 | | - }); | 107 | | - | 108 | 65 | test('flushes passive effects synchronously when they are the result of a sync render', async () => { | 109 | 66 | function App() { | 110 | 67 | useEffect(() => { | |
|