Skip to content

Commit

Permalink
Noop unstable_batchedUpdates
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Jan 27, 2024
1 parent c98cac9 commit c6a06f7
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/react-dom/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export {
hydrate,
render,
unmountComponentAtNode,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
Expand All @@ -42,4 +41,6 @@ export {
version,
} from './src/client/ReactDOM';

export {unstable_batchedUpdates} from './src/client/ReactDOMLegacy';

export {Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED};
3 changes: 2 additions & 1 deletion packages/react-dom/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export {
createRoot,
hydrateRoot,
flushSync,
unstable_batchedUpdates,
unstable_createEventHandle,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
useFormStatus,
Expand All @@ -26,3 +25,5 @@ export {
preinitModule,
version,
} from './src/client/ReactDOM';

export {unstable_batchedUpdates} from './src/client/ReactDOMLegacy';
1 change: 1 addition & 0 deletions packages/react-dom/src/__tests__/ReactLegacyMount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ describe('ReactMount', () => {
expect(calls).toBe(5);
});

// @gate www
it('initial mount of legacy root is sync inside batchedUpdates, as if it were wrapped in flushSync', () => {
const container1 = document.createElement('div');
const container2 = document.createElement('div');
Expand Down
9 changes: 9 additions & 0 deletions packages/react-dom/src/__tests__/ReactLegacyUpdates-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe('ReactLegacyUpdates', () => {
assertLog = InternalTestUtils.assertLog;
});

// @gate www
it('should batch state when updating state twice', () => {
let updateCount = 0;

Expand Down Expand Up @@ -60,6 +61,7 @@ describe('ReactLegacyUpdates', () => {
expect(updateCount).toBe(1);
});

// @gate www
it('should batch state when updating two different state keys', () => {
let updateCount = 0;

Expand Down Expand Up @@ -92,6 +94,7 @@ describe('ReactLegacyUpdates', () => {
expect(updateCount).toBe(1);
});

// @gate www
it('should batch state and props together', () => {
let updateCount = 0;

Expand Down Expand Up @@ -125,6 +128,7 @@ describe('ReactLegacyUpdates', () => {
expect(updateCount).toBe(1);
});

// @gate www
it('should batch parent/child state updates together', () => {
let parentUpdateCount = 0;

Expand Down Expand Up @@ -179,6 +183,7 @@ describe('ReactLegacyUpdates', () => {
expect(childUpdateCount).toBe(1);
});

// @gate www
it('should batch child/parent state updates together', () => {
let parentUpdateCount = 0;

Expand Down Expand Up @@ -235,6 +240,7 @@ describe('ReactLegacyUpdates', () => {
expect(childUpdateCount).toBe(1);
});

// @gate www
it('should support chained state updates', () => {
let updateCount = 0;

Expand Down Expand Up @@ -274,6 +280,7 @@ describe('ReactLegacyUpdates', () => {
expect(updateCount).toBe(2);
});

// @gate www
it('should batch forceUpdate together', () => {
let shouldUpdateCount = 0;
let updateCount = 0;
Expand Down Expand Up @@ -530,6 +537,7 @@ describe('ReactLegacyUpdates', () => {
);
});

// @gate www
it('should queue mount-ready handlers across different roots', () => {
// We'll define two components A and B, then update both of them. When A's
// componentDidUpdate handlers is called, B's DOM should already have been
Expand Down Expand Up @@ -817,6 +825,7 @@ describe('ReactLegacyUpdates', () => {
expect(callbackCount).toBe(1);
});

// @gate www
it('does not call render after a component as been deleted', () => {
let renderCount = 0;
let componentB = null;
Expand Down
8 changes: 6 additions & 2 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
findDOMNode,
render,
hydrate,
batchedUpdates,
unstable_renderSubtreeIntoContainer,
unmountComponentAtNode,
} from './ReactDOMLegacy';
Expand All @@ -33,7 +34,6 @@ import {
import {createEventHandle} from 'react-dom-bindings/src/client/ReactDOMEventHandle';

import {
batchedUpdates,
flushSync as flushSyncWithoutWarningIfAlreadyRendering,
isAlreadyRendering,
injectIntoDevTools,
Expand Down Expand Up @@ -165,9 +165,13 @@ function flushSync<R>(fn: (() => R) | void): R | void {
return flushSyncWithoutWarningIfAlreadyRendering(fn);
}

function unstable_batchedUpdates<A, R>(fn: (a: A) => R, a: A): R {
return fn(a);
}

export {
createPortal,
batchedUpdates as unstable_batchedUpdates,
unstable_batchedUpdates,
flushSync,
ReactVersion as version,
// Disabled behind disableLegacyReactDOMAPIs
Expand Down
3 changes: 3 additions & 0 deletions packages/react-dom/src/client/ReactDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
} from 'react-dom-bindings/src/client/HTMLNodeType';

import {
batchedUpdates,
createContainer,
createHydrationContainer,
findHostInstanceWithNoPortals,
Expand Down Expand Up @@ -442,3 +443,5 @@ export function unmountComponentAtNode(container: Container): boolean {
return false;
}
}

export {batchedUpdates as unstable_batchedUpdates};

0 comments on commit c6a06f7

Please sign in to comment.