Skip to content

Commit

Permalink
[DOM] Add unstable_batchedUpdates to server-rendering-stub (facebook#…
Browse files Browse the repository at this point in the history
…27028)

`unstable_batchedUpdates` shouldn't really be called on the server but
the semantics are clear enough and we can provide a trivial
implementation that calls the provided callback so we are adding it to
the server-rendering-stub.

This means we will also keep it around when we make the top level
react-dom exports match the server-rendering-stub in the next major
  • Loading branch information
gnoff authored and AndyPengc12 committed Apr 15, 2024
1 parent 40f9658 commit 63cd14e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/react-dom/server-rendering-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ export {
preload,
preinit,
experimental_useFormStatus,
unstable_batchedUpdates,
} from './src/server/ReactDOMServerRenderingStub';
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('react-dom-server-rendering-stub', () => {
expect(ReactDOM.hydrate).toBe(undefined);
expect(ReactDOM.render).toBe(undefined);
expect(ReactDOM.unmountComponentAtNode).toBe(undefined);
expect(ReactDOM.unstable_batchedUpdates).toBe(undefined);
expect(ReactDOM.unstable_createEventHandle).toBe(undefined);
expect(ReactDOM.unstable_renderSubtreeIntoContainer).toBe(undefined);
expect(ReactDOM.unstable_runWithPriority).toBe(undefined);
Expand Down
10 changes: 10 additions & 0 deletions packages/react-dom/src/server/ReactDOMServerRenderingStub.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ export function flushSync() {
' to not call flushSync no the server.',
);
}

// on the server we just call the callback because there is
// not update mechanism. Really this should not be called on the
// server but since the semantics are generally clear enough we
// can provide this trivial implementation.
function batchedUpdates<A, R>(fn: A => R, a: A): R {
return fn(a);
}

export {batchedUpdates as unstable_batchedUpdates};

0 comments on commit 63cd14e

Please sign in to comment.