Skip to content

Commit 75941c4

Browse files
committed
The cost of the separate file is not really warranted. Will use feature flag to scope build specific implementations
1 parent 8b62c73 commit 75941c4

File tree

3 files changed

+28
-219
lines changed

3 files changed

+28
-219
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export {
3232
preinit,
3333
preinitModule,
3434
version,
35-
} from './src/client/ReactDOMFB';
35+
} from './src/client/ReactDOM';
3636

3737
export {
3838
createRoot,

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ import type {
1414
CreateRootOptions,
1515
} from './ReactDOMRoot';
1616

17+
import {disableLegacyMode} from 'shared/ReactFeatureFlags';
1718
import {
1819
createRoot as createRootImpl,
1920
hydrateRoot as hydrateRootImpl,
2021
isValidContainer,
2122
} from './ReactDOMRoot';
2223
import {createEventHandle} from 'react-dom-bindings/src/client/ReactDOMEventHandle';
23-
import {flushSync} from '../shared/ReactDOMFlushSync';
24+
import {flushSync as flushSyncIsomorphic} from '../shared/ReactDOMFlushSync';
2425

2526
import {
27+
flushSyncFromReconciler as flushSyncWithoutWarningIfAlreadyRendering,
28+
isAlreadyRendering,
2629
injectIntoDevTools,
2730
findHostInstance,
2831
} from 'react-reconciler/src/ReactFiberReconciler';
@@ -120,6 +123,29 @@ function hydrateRoot(
120123
return hydrateRootImpl(container, initialChildren, options);
121124
}
122125

126+
// Overload the definition to the two valid signatures.
127+
// Warning, this opts-out of checking the function body.
128+
declare function flushSyncFromReconciler<R>(fn: () => R): R;
129+
// eslint-disable-next-line no-redeclare
130+
declare function flushSyncFromReconciler(): void;
131+
// eslint-disable-next-line no-redeclare
132+
function flushSyncFromReconciler<R>(fn: (() => R) | void): R | void {
133+
if (__DEV__) {
134+
if (isAlreadyRendering()) {
135+
console.error(
136+
'flushSync was called from inside a lifecycle method. React cannot ' +
137+
'flush when React is already rendering. Consider moving this call to ' +
138+
'a scheduler task or micro task.',
139+
);
140+
}
141+
}
142+
return flushSyncWithoutWarningIfAlreadyRendering(fn);
143+
}
144+
145+
const flushSync: typeof flushSyncIsomorphic = disableLegacyMode
146+
? flushSyncIsomorphic
147+
: flushSyncFromReconciler;
148+
123149
function findDOMNode(
124150
componentOrElement: React$Component<any, any>,
125151
): null | Element | Text {

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

Lines changed: 0 additions & 217 deletions
This file was deleted.

0 commit comments

Comments
 (0)