Skip to content

Commit b383fae

Browse files
committed
Noop unstable_batchedUpdates
1 parent 8436bcc commit b383fae

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

packages/react-dom/index.classic.fb.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export {
2323
findDOMNode,
2424
flushSync,
2525
unmountComponentAtNode,
26-
unstable_batchedUpdates,
2726
unstable_createEventHandle,
2827
unstable_renderSubtreeIntoContainer,
2928
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
@@ -38,6 +37,11 @@ export {
3837
version,
3938
} from './src/client/ReactDOM';
4039

41-
export {createRoot, hydrateRoot, render} from './src/client/ReactDOMRootFB';
40+
export {
41+
createRoot,
42+
hydrateRoot,
43+
render,
44+
unstable_batchedUpdates,
45+
} from './src/client/ReactDOMRootFB';
4246

4347
export {Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED};

packages/react-dom/src/client/ReactDOM.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import {
3232
import {createEventHandle} from 'react-dom-bindings/src/client/ReactDOMEventHandle';
3333

3434
import {
35-
batchedUpdates,
3635
flushSync as flushSyncWithoutWarningIfAlreadyRendering,
3736
isAlreadyRendering,
3837
injectIntoDevTools,
@@ -164,9 +163,16 @@ function flushSync<R>(fn: (() => R) | void): R | void {
164163
return flushSyncWithoutWarningIfAlreadyRendering(fn);
165164
}
166165

166+
function unstable_batchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
167+
// batchedUpdates was a legacy mode feature that is a no-op outside of
168+
// legacy mode. In 19, we made it an actual no-op, but we're keeping it
169+
// for now since there may be libraries that still include it.
170+
return fn(a);
171+
}
172+
167173
export {
168174
createPortal,
169-
batchedUpdates as unstable_batchedUpdates,
175+
unstable_batchedUpdates,
170176
flushSync,
171177
ReactVersion as version,
172178
// Disabled behind disableLegacyReactDOMAPIs
@@ -193,7 +199,7 @@ Internals.Events = [
193199
getFiberCurrentPropsFromNode,
194200
enqueueStateRestore,
195201
restoreStateIfNeeded,
196-
batchedUpdates,
202+
unstable_batchedUpdates,
197203
];
198204

199205
const foundDevTools = injectIntoDevTools({

packages/react-dom/src/client/ReactDOMRootFB.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import {
4242
} from 'react-dom-bindings/src/client/HTMLNodeType';
4343

4444
import {
45+
batchedUpdates,
4546
createContainer,
4647
createHydrationContainer,
4748
findHostInstanceWithNoPortals,
@@ -416,3 +417,5 @@ export function unstable_renderSubtreeIntoContainer(
416417
callback,
417418
);
418419
}
420+
421+
export {batchedUpdates as unstable_batchedUpdates};

packages/react-reconciler/src/ReactFiberWorkLoop.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
disableLegacyContext,
4040
alwaysThrottleRetries,
4141
enableInfiniteRenderLoopDetection,
42+
disableLegacyMode,
4243
} from 'shared/ReactFeatureFlags';
4344
import ReactSharedInternals from 'shared/ReactSharedInternals';
4445
import is from 'shared/objectIs';
@@ -1455,21 +1456,27 @@ export function deferredUpdates<A>(fn: () => A): A {
14551456
}
14561457

14571458
export function batchedUpdates<A, R>(fn: A => R, a: A): R {
1458-
const prevExecutionContext = executionContext;
1459-
executionContext |= BatchedContext;
1460-
try {
1459+
if (disableLegacyMode) {
1460+
// batchedUpdates is a no-op now, but there's still some internal react-dom
1461+
// code calling it, that we can't remove until we remove legacy mode.
14611462
return fn(a);
1462-
} finally {
1463-
executionContext = prevExecutionContext;
1464-
// If there were legacy sync updates, flush them at the end of the outer
1465-
// most batchedUpdates-like method.
1466-
if (
1467-
executionContext === NoContext &&
1468-
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
1469-
!(__DEV__ && ReactCurrentActQueue.isBatchingLegacy)
1470-
) {
1471-
resetRenderTimer();
1472-
flushSyncWorkOnLegacyRootsOnly();
1463+
} else {
1464+
const prevExecutionContext = executionContext;
1465+
executionContext |= BatchedContext;
1466+
try {
1467+
return fn(a);
1468+
} finally {
1469+
executionContext = prevExecutionContext;
1470+
// If there were legacy sync updates, flush them at the end of the outer
1471+
// most batchedUpdates-like method.
1472+
if (
1473+
executionContext === NoContext &&
1474+
// Treat `act` as if it's inside `batchedUpdates`, even in legacy mode.
1475+
!(__DEV__ && ReactCurrentActQueue.isBatchingLegacy)
1476+
) {
1477+
resetRenderTimer();
1478+
flushSyncWorkOnLegacyRootsOnly();
1479+
}
14731480
}
14741481
}
14751482
}

0 commit comments

Comments
 (0)