Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move unstable_scheduleHydration to ReactDOMHydrationRoot #22455

Merged
merged 8 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-dom/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ export {
unstable_isNewReconciler,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
unstable_scheduleHydration,
version,
} from './src/client/ReactDOM';
1 change: 0 additions & 1 deletion packages/react-dom/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ export {
unstable_flushControlled,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
unstable_scheduleHydration,
version,
} from './src/client/ReactDOM';
1 change: 0 additions & 1 deletion packages/react-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ export {
unstable_isNewReconciler,
unstable_renderSubtreeIntoContainer,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
unstable_scheduleHydration,
version,
} from './src/client/ReactDOM';
1 change: 0 additions & 1 deletion packages/react-dom/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ export {
unstable_flushControlled,
unstable_isNewReconciler,
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
unstable_scheduleHydration,
version,
} from './src/client/ReactDOM';
Original file line number Diff line number Diff line change
Expand Up @@ -1561,10 +1561,9 @@ describe('ReactDOMServerPartialHydration', () => {
const b = container.getElementsByTagName('span')[1];
expect(b.textContent).toBe('B');

const root = ReactDOM.createRoot(container, {hydrate: true});

const root = ReactDOM.hydrateRoot(container);
salazarm marked this conversation as resolved.
Show resolved Hide resolved
// Increase hydration priority to higher than "offscreen".
ReactDOM.unstable_scheduleHydration(b);
root.unstable_scheduleHydration(b);

suspend = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,14 @@ describe('ReactDOMServerSelectiveHydration', () => {
const spanB = container.getElementsByTagName('span')[1];
const spanC = container.getElementsByTagName('span')[2];

const root = ReactDOM.createRoot(container, {hydrate: true});
root.render(<App />);
const root = ReactDOM.hydrateRoot(container, <App />);

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

// Increase priority of B and then C.
ReactDOM.unstable_scheduleHydration(spanB);
ReactDOM.unstable_scheduleHydration(spanC);
root.unstable_scheduleHydration(spanB);
root.unstable_scheduleHydration(spanC);

// We should prioritize hydrating C first because the last added
// gets highest priority followed by the next added.
Expand Down
8 changes: 0 additions & 8 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import {
setAttemptDiscreteHydration,
setAttemptContinuousHydration,
setAttemptHydrationAtCurrentPriority,
queueExplicitHydrationTarget,
setGetCurrentUpdatePriority,
setAttemptHydrationAtPriority,
} from '../events/ReactDOMEventReplaying';
Expand Down Expand Up @@ -117,12 +116,6 @@ function createPortal(
return createPortalImpl(children, container, null, key);
}

function scheduleHydration(target: Node) {
if (target) {
queueExplicitHydrationTarget(target);
}
}

function renderSubtreeIntoContainer(
parentComponent: React$Component<any, any>,
element: React$Element<any>,
Expand Down Expand Up @@ -197,7 +190,6 @@ export {
createRoot,
hydrateRoot,
flushControlled as unstable_flushControlled,
scheduleHydration as unstable_scheduleHydration,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
// enableCreateEventHandleAPI
Expand Down
16 changes: 15 additions & 1 deletion packages/react-dom/src/client/ReactDOMRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type {Container} from './ReactDOMHostConfig';
import type {MutableSource, ReactNodeList} from 'shared/ReactTypes';
import type {FiberRoot} from 'react-reconciler/src/ReactInternalTypes';

import {queueExplicitHydrationTarget} from '../events/ReactDOMEventReplaying';

export type RootType = {
render(children: ReactNodeList): void,
unmount(): void,
Expand Down Expand Up @@ -190,6 +192,18 @@ export function createRoot(
return new ReactDOMRoot(root);
}

function ReactDOMHydrationRoot(internalRoot: FiberRoot) {
ReactDOMRoot.call(this, internalRoot);
}
function scheduleHydration(target: Node) {
if (target) {
queueExplicitHydrationTarget(target);
}
}
Object.assign(ReactDOMHydrationRoot.prototype, ReactDOMRoot.prototype, {
salazarm marked this conversation as resolved.
Show resolved Hide resolved
unstable_scheduleHydration: scheduleHydration,
});

export function hydrateRoot(
container: Container,
initialChildren: ReactNodeList,
Expand Down Expand Up @@ -237,7 +251,7 @@ export function hydrateRoot(
// Render the initial children
updateContainer(initialChildren, root, null, null);

return new ReactDOMRoot(root);
return new ReactDOMHydrationRoot(root);
}

export function isValidContainer(node: any): boolean {
Expand Down