Skip to content

Commit 4ff5f57

Browse files
authored
Move unstable_scheduleHydration to ReactDOMHydrationRoot (#22455)
* move unstable_scheduleHydration to ReactDOMHydrationRoot * move definition of schedule hydration * fix test? * prototype * fix test * remove gating because unstable_scheduleHydration is no longer gated through index.stable.js because its exposed through ReactDOMHydrationRoot instead of the ReactDOM package * remove another gating
1 parent ee8f146 commit 4ff5f57

8 files changed

+22
-23
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ export {
3434
unstable_isNewReconciler,
3535
unstable_renderSubtreeIntoContainer,
3636
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
37-
unstable_scheduleHydration,
3837
version,
3938
} from './src/client/ReactDOM';

packages/react-dom/index.experimental.js

-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ export {
2121
unstable_flushControlled,
2222
unstable_renderSubtreeIntoContainer,
2323
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
24-
unstable_scheduleHydration,
2524
version,
2625
} from './src/client/ReactDOM';

packages/react-dom/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ export {
2525
unstable_isNewReconciler,
2626
unstable_renderSubtreeIntoContainer,
2727
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
28-
unstable_scheduleHydration,
2928
version,
3029
} from './src/client/ReactDOM';

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

-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ export {
1818
unstable_flushControlled,
1919
unstable_isNewReconciler,
2020
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
21-
unstable_scheduleHydration,
2221
version,
2322
} from './src/client/ReactDOM';

packages/react-dom/src/__tests__/ReactDOMServerPartialHydration-test.internal.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1771,10 +1771,9 @@ describe('ReactDOMServerPartialHydration', () => {
17711771
const b = container.getElementsByTagName('span')[1];
17721772
expect(b.textContent).toBe('B');
17731773

1774-
const root = ReactDOM.createRoot(container, {hydrate: true});
1775-
1774+
const root = ReactDOM.hydrateRoot(container, <App />);
17761775
// Increase hydration priority to higher than "offscreen".
1777-
ReactDOM.unstable_scheduleHydration(b);
1776+
root.unstable_scheduleHydration(b);
17781777

17791778
suspend = true;
17801779

packages/react-dom/src/__tests__/ReactDOMServerSelectiveHydration-test.internal.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,6 @@ describe('ReactDOMServerSelectiveHydration', () => {
886886
document.body.removeChild(container);
887887
});
888888

889-
// @gate experimental || www
890889
it('hydrates the last explicitly hydrated target at higher priority', async () => {
891890
function Child({text}) {
892891
Scheduler.unstable_yieldValue(text);
@@ -920,15 +919,14 @@ describe('ReactDOMServerSelectiveHydration', () => {
920919
const spanB = container.getElementsByTagName('span')[1];
921920
const spanC = container.getElementsByTagName('span')[2];
922921

923-
const root = ReactDOM.createRoot(container, {hydrate: true});
924-
root.render(<App />);
922+
const root = ReactDOM.hydrateRoot(container, <App />);
925923

926924
// Nothing has been hydrated so far.
927925
expect(Scheduler).toHaveYielded([]);
928926

929927
// Increase priority of B and then C.
930-
ReactDOM.unstable_scheduleHydration(spanB);
931-
ReactDOM.unstable_scheduleHydration(spanC);
928+
root.unstable_scheduleHydration(spanB);
929+
root.unstable_scheduleHydration(spanC);
932930

933931
// We should prioritize hydrating C first because the last added
934932
// gets highest priority followed by the next added.

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

-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import {
5656
setAttemptDiscreteHydration,
5757
setAttemptContinuousHydration,
5858
setAttemptHydrationAtCurrentPriority,
59-
queueExplicitHydrationTarget,
6059
setGetCurrentUpdatePriority,
6160
setAttemptHydrationAtPriority,
6261
} from '../events/ReactDOMEventReplaying';
@@ -116,12 +115,6 @@ function createPortal(
116115
return createPortalImpl(children, container, null, key);
117116
}
118117

119-
function scheduleHydration(target: Node) {
120-
if (target) {
121-
queueExplicitHydrationTarget(target);
122-
}
123-
}
124-
125118
function renderSubtreeIntoContainer(
126119
parentComponent: React$Component<any, any>,
127120
element: React$Element<any>,
@@ -196,7 +189,6 @@ export {
196189
createRoot,
197190
hydrateRoot,
198191
flushControlled as unstable_flushControlled,
199-
scheduleHydration as unstable_scheduleHydration,
200192
// Disabled behind disableUnstableRenderSubtreeIntoContainer
201193
renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
202194
// enableCreateEventHandleAPI

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type {Container} from './ReactDOMHostConfig';
1111
import type {MutableSource, ReactNodeList} from 'shared/ReactTypes';
1212
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';
1313

14+
import {queueExplicitHydrationTarget} from '../events/ReactDOMEventReplaying';
15+
1416
export type RootType = {
1517
render(children: ReactNodeList): void,
1618
unmount(): void,
@@ -72,7 +74,9 @@ function ReactDOMRoot(internalRoot: FiberRoot) {
7274
this._internalRoot = internalRoot;
7375
}
7476

75-
ReactDOMRoot.prototype.render = function(children: ReactNodeList): void {
77+
ReactDOMHydrationRoot.prototype.render = ReactDOMRoot.prototype.render = function(
78+
children: ReactNodeList,
79+
): void {
7680
const root = this._internalRoot;
7781
if (root === null) {
7882
throw new Error('Cannot update an unmounted root.');
@@ -104,7 +108,7 @@ ReactDOMRoot.prototype.render = function(children: ReactNodeList): void {
104108
updateContainer(children, root, null, null);
105109
};
106110

107-
ReactDOMRoot.prototype.unmount = function(): void {
111+
ReactDOMHydrationRoot.prototype.unmount = ReactDOMRoot.prototype.unmount = function(): void {
108112
if (__DEV__) {
109113
if (typeof arguments[0] === 'function') {
110114
console.error(
@@ -189,6 +193,16 @@ export function createRoot(
189193
return new ReactDOMRoot(root);
190194
}
191195

196+
function ReactDOMHydrationRoot(internalRoot: FiberRoot) {
197+
this._internalRoot = internalRoot;
198+
}
199+
function scheduleHydration(target: Node) {
200+
if (target) {
201+
queueExplicitHydrationTarget(target);
202+
}
203+
}
204+
ReactDOMHydrationRoot.prototype.unstable_scheduleHydration = scheduleHydration;
205+
192206
export function hydrateRoot(
193207
container: Container,
194208
initialChildren: ReactNodeList,
@@ -236,7 +250,7 @@ export function hydrateRoot(
236250
// Render the initial children
237251
updateContainer(initialChildren, root, null, null);
238252

239-
return new ReactDOMRoot(root);
253+
return new ReactDOMHydrationRoot(root);
240254
}
241255

242256
export function isValidContainer(node: any): boolean {

0 commit comments

Comments
 (0)