diff --git a/packages/react-dom-bindings/src/client/ReactDOMComponent.js b/packages/react-dom-bindings/src/client/ReactDOMComponent.js index cc773dea4de36..d662f107dd2d9 100644 --- a/packages/react-dom-bindings/src/client/ReactDOMComponent.js +++ b/packages/react-dom-bindings/src/client/ReactDOMComponent.js @@ -327,7 +327,6 @@ function normalizeMarkupForTextOrAttribute(markup: mixed): string { export function checkForUnmatchedText( serverText: string, clientText: string | number, - isConcurrentMode: boolean, shouldWarnDev: boolean, ) { const normalizedClientText = normalizeMarkupForTextOrAttribute(clientText); @@ -349,7 +348,7 @@ export function checkForUnmatchedText( } } - if (isConcurrentMode && enableClientRenderFallbackOnTextMismatch) { + if (enableClientRenderFallbackOnTextMismatch) { // In concurrent roots, we throw when there's a text mismatch and revert to // client rendering, up to the nearest Suspense boundary. throw new Error('Text content does not match server-rendered HTML.'); @@ -2706,7 +2705,6 @@ export function diffHydratedProperties( domElement: Element, tag: string, props: Object, - isConcurrentMode: boolean, shouldWarnDev: boolean, hostContext: HostContext, ): void { @@ -2820,14 +2818,9 @@ export function diffHydratedProperties( if (typeof children === 'string' || typeof children === 'number') { if (domElement.textContent !== '' + children) { if (props.suppressHydrationWarning !== true) { - checkForUnmatchedText( - domElement.textContent, - children, - isConcurrentMode, - shouldWarnDev, - ); + checkForUnmatchedText(domElement.textContent, children, shouldWarnDev); } - if (!isConcurrentMode || !enableClientRenderFallbackOnTextMismatch) { + if (!enableClientRenderFallbackOnTextMismatch) { // We really should be patching this in the commit phase but since // this only affects legacy mode hydration which is deprecated anyway // we can get away with it. @@ -2896,11 +2889,7 @@ export function diffHydratedProperties( } } -export function diffHydratedText( - textNode: Text, - text: string, - isConcurrentMode: boolean, -): boolean { +export function diffHydratedText(textNode: Text, text: string): boolean { const isDifferent = textNode.nodeValue !== text; return isDifferent; } diff --git a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js index 9e2c5e41c062f..e324891230e8d 100644 --- a/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +++ b/packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js @@ -31,8 +31,6 @@ import type { import {NotPending} from 'react-dom-bindings/src/shared/ReactDOMFormActions'; import {getCurrentRootHostContainer} from 'react-reconciler/src/ReactFiberHostContext'; import {DefaultEventPriority} from 'react-reconciler/src/ReactEventPriorities'; -// TODO: Remove this deep import when we delete the legacy root API -import {ConcurrentMode, NoMode} from 'react-reconciler/src/ReactTypeOfMode'; import hasOwnProperty from 'shared/hasOwnProperty'; import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion'; @@ -1381,19 +1379,7 @@ export function hydrateInstance( // get attached. updateFiberProps(instance, props); - // TODO: Temporary hack to check if we're in a concurrent root. We can delete - // when the legacy root API is removed. - const isConcurrentMode = - ((internalInstanceHandle: Fiber).mode & ConcurrentMode) !== NoMode; - - diffHydratedProperties( - instance, - type, - props, - isConcurrentMode, - shouldWarnDev, - hostContext, - ); + diffHydratedProperties(instance, type, props, shouldWarnDev, hostContext); } export function validateHydratableTextInstance( @@ -1418,12 +1404,7 @@ export function hydrateTextInstance( ): boolean { precacheFiberNode(internalInstanceHandle, textInstance); - // TODO: Temporary hack to check if we're in a concurrent root. We can delete - // when the legacy root API is removed. - const isConcurrentMode = - ((internalInstanceHandle: Fiber).mode & ConcurrentMode) !== NoMode; - - return diffHydratedText(textInstance, text, isConcurrentMode); + return diffHydratedText(textInstance, text); } export function hydrateSuspenseInstance( @@ -1521,15 +1502,9 @@ export function didNotMatchHydratedContainerTextInstance( parentContainer: Container, textInstance: TextInstance, text: string, - isConcurrentMode: boolean, shouldWarnDev: boolean, ) { - checkForUnmatchedText( - textInstance.nodeValue, - text, - isConcurrentMode, - shouldWarnDev, - ); + checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev); } export function didNotMatchHydratedTextInstance( @@ -1538,16 +1513,10 @@ export function didNotMatchHydratedTextInstance( parentInstance: Instance, textInstance: TextInstance, text: string, - isConcurrentMode: boolean, shouldWarnDev: boolean, ) { if (parentProps[SUPPRESS_HYDRATION_WARNING] !== true) { - checkForUnmatchedText( - textInstance.nodeValue, - text, - isConcurrentMode, - shouldWarnDev, - ); + checkForUnmatchedText(textInstance.nodeValue, text, shouldWarnDev); } } @@ -1590,17 +1559,14 @@ export function didNotHydrateInstance( parentProps: Props, parentInstance: Instance, instance: HydratableInstance, - isConcurrentMode: boolean, ) { if (__DEV__) { - if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) { - if (instance.nodeType === ELEMENT_NODE) { - warnForDeletedHydratableElement(parentInstance, (instance: any)); - } else if (instance.nodeType === COMMENT_NODE) { - // TODO: warnForDeletedHydratableSuspenseBoundary - } else { - warnForDeletedHydratableText(parentInstance, (instance: any)); - } + if (instance.nodeType === ELEMENT_NODE) { + warnForDeletedHydratableElement(parentInstance, (instance: any)); + } else if (instance.nodeType === COMMENT_NODE) { + // TODO: warnForDeletedHydratableSuspenseBoundary + } else { + warnForDeletedHydratableText(parentInstance, (instance: any)); } } } @@ -1671,12 +1637,9 @@ export function didNotFindHydratableInstance( parentInstance: Instance, type: string, props: Props, - isConcurrentMode: boolean, ) { if (__DEV__) { - if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) { - warnForInsertedHydratedElement(parentInstance, type, props); - } + warnForInsertedHydratedElement(parentInstance, type, props); } } @@ -1685,12 +1648,9 @@ export function didNotFindHydratableTextInstance( parentProps: Props, parentInstance: Instance, text: string, - isConcurrentMode: boolean, ) { if (__DEV__) { - if (isConcurrentMode || parentProps[SUPPRESS_HYDRATION_WARNING] !== true) { - warnForInsertedHydratedText(parentInstance, text); - } + warnForInsertedHydratedText(parentInstance, text); } } diff --git a/packages/react-dom/index.classic.fb.js b/packages/react-dom/index.classic.fb.js index d8814243b690d..b5e974f2b5f25 100644 --- a/packages/react-dom/index.classic.fb.js +++ b/packages/react-dom/index.classic.fb.js @@ -24,7 +24,6 @@ export { hydrateRoot, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/index.experimental.js b/packages/react-dom/index.experimental.js index 012eb6866e8a4..5849dd4f41033 100644 --- a/packages/react-dom/index.experimental.js +++ b/packages/react-dom/index.experimental.js @@ -14,7 +14,6 @@ export { hydrateRoot, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/index.js b/packages/react-dom/index.js index 4db349ea5bf0d..0c55c3a92219a 100644 --- a/packages/react-dom/index.js +++ b/packages/react-dom/index.js @@ -16,7 +16,6 @@ export { hydrateRoot, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/index.stable.js b/packages/react-dom/index.stable.js index 36f5563fda5da..5e5a5fe275d95 100644 --- a/packages/react-dom/index.stable.js +++ b/packages/react-dom/index.stable.js @@ -14,7 +14,6 @@ export { hydrateRoot, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/src/client/ReactDOM.js b/packages/react-dom/src/client/ReactDOM.js index f2e4c626070f4..4a50fbaaba2ba 100644 --- a/packages/react-dom/src/client/ReactDOM.js +++ b/packages/react-dom/src/client/ReactDOM.js @@ -21,7 +21,6 @@ import type { import { findDOMNode, render, - hydrate, unstable_renderSubtreeIntoContainer, unmountComponentAtNode, } from './ReactDOMLegacy'; @@ -172,7 +171,6 @@ export { ReactVersion as version, // Disabled behind disableLegacyReactDOMAPIs findDOMNode, - hydrate, render, unmountComponentAtNode, // exposeConcurrentModeAPIs diff --git a/packages/react-dom/src/client/ReactDOMLegacy.js b/packages/react-dom/src/client/ReactDOMLegacy.js index 9a7934dc21576..5b5abd6f5350f 100644 --- a/packages/react-dom/src/client/ReactDOMLegacy.js +++ b/packages/react-dom/src/client/ReactDOMLegacy.js @@ -259,46 +259,6 @@ export function findDOMNode( return findHostInstance(componentOrElement); } -export function hydrate( - element: React$Node, - container: Container, - callback: ?Function, -): React$Component | PublicInstance | null { - if (__DEV__) { - console.error( - 'ReactDOM.hydrate is no longer supported in React 18. Use hydrateRoot ' + - 'instead. Until you switch to the new API, your app will behave as ' + - "if it's running React 17. Learn " + - 'more: https://reactjs.org/link/switch-to-createroot', - ); - } - - if (!isValidContainerLegacy(container)) { - throw new Error('Target container is not a DOM element.'); - } - - if (__DEV__) { - const isModernRoot = - isContainerMarkedAsRoot(container) && - container._reactRootContainer === undefined; - if (isModernRoot) { - console.error( - 'You are calling ReactDOM.hydrate() on a container that was previously ' + - 'passed to ReactDOMClient.createRoot(). This is not supported. ' + - 'Did you mean to call hydrateRoot(container, element)?', - ); - } - } - // TODO: throw or warn if we couldn't hydrate? - return legacyRenderSubtreeIntoContainer( - null, - element, - container, - true, - callback, - ); -} - export function render( element: React$Element, container: Container, diff --git a/packages/react-dom/unstable_testing.classic.fb.js b/packages/react-dom/unstable_testing.classic.fb.js index 6dd68f3669dc3..9958b22cc3277 100644 --- a/packages/react-dom/unstable_testing.classic.fb.js +++ b/packages/react-dom/unstable_testing.classic.fb.js @@ -11,7 +11,6 @@ export { createPortal, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/unstable_testing.experimental.js b/packages/react-dom/unstable_testing.experimental.js index b84561272bef3..2523a710ec75a 100644 --- a/packages/react-dom/unstable_testing.experimental.js +++ b/packages/react-dom/unstable_testing.experimental.js @@ -11,7 +11,6 @@ export { createPortal, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/unstable_testing.js b/packages/react-dom/unstable_testing.js index 9729a427e4aa6..080b7340d11b2 100644 --- a/packages/react-dom/unstable_testing.js +++ b/packages/react-dom/unstable_testing.js @@ -11,7 +11,6 @@ export { createPortal, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-dom/unstable_testing.stable.js b/packages/react-dom/unstable_testing.stable.js index 453e8b4fdece7..855f6f1fc006a 100644 --- a/packages/react-dom/unstable_testing.stable.js +++ b/packages/react-dom/unstable_testing.stable.js @@ -11,7 +11,6 @@ export { createPortal, findDOMNode, flushSync, - hydrate, render, unmountComponentAtNode, unstable_batchedUpdates, diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 982e8b5905456..7fdc2f9ce4014 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -850,12 +850,6 @@ export function createFiberFromText( return fiber; } -export function createFiberFromHostInstanceForDeletion(): Fiber { - const fiber = createFiber(HostComponent, null, null, NoMode); - fiber.elementType = 'DELETED'; - return fiber; -} - export function createFiberFromDehydratedFragment( dehydratedNode: SuspenseInstance, ): Fiber { diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 3e7d3693ded9b..2196acde4552d 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -143,7 +143,6 @@ import { import { NoLane, NoLanes, - SyncLane, OffscreenLane, DefaultHydrationLane, SomeRetryLane, @@ -2738,18 +2737,7 @@ function mountDehydratedSuspenseComponent( ): null | Fiber { // During the first pass, we'll bail out and not drill into the children. // Instead, we'll leave the content in place and try to hydrate it later. - if ((workInProgress.mode & ConcurrentMode) === NoMode) { - if (__DEV__) { - console.error( - 'Cannot hydrate Suspense in legacy mode. Switch from ' + - 'ReactDOM.hydrate(element, container) to ' + - 'ReactDOMClient.hydrateRoot(container, )' + - '.render(element) or remove the Suspense components from ' + - 'the server rendered components.', - ); - } - workInProgress.lanes = laneToLanes(SyncLane); - } else if (isSuspenseInstanceFallback(suspenseInstance)) { + if (isSuspenseInstanceFallback(suspenseInstance)) { // This is a client-only boundary. Since we won't get any content from the server // for this, we need to schedule that at a higher priority based on when it would // have timed out. In theory we could render it in this pass but it would have the @@ -2789,15 +2777,6 @@ function updateDehydratedSuspenseComponent( // but after we've already committed once. warnIfHydrating(); - if ((workInProgress.mode & ConcurrentMode) === NoMode) { - return retrySuspenseComponentWithoutHydrating( - current, - workInProgress, - renderLanes, - null, - ); - } - if (isSuspenseInstanceFallback(suspenseInstance)) { // This boundary is in a permanent fallback state. In this case, we'll never // get an update and we'll never be able to hydrate the final content. Let's just try the diff --git a/packages/react-reconciler/src/ReactFiberCompleteWork.js b/packages/react-reconciler/src/ReactFiberCompleteWork.js index a2daff05de72e..628dc1755d18f 100644 --- a/packages/react-reconciler/src/ReactFiberCompleteWork.js +++ b/packages/react-reconciler/src/ReactFiberCompleteWork.js @@ -868,7 +868,6 @@ function completeDehydratedSuspenseBoundary( ): boolean { if ( hasUnhydratedTailNodes() && - (workInProgress.mode & ConcurrentMode) !== NoMode && (workInProgress.flags & DidCapture) === NoFlags ) { warnIfUnhydratedTailNodes(workInProgress); diff --git a/packages/react-reconciler/src/ReactFiberHydrationContext.js b/packages/react-reconciler/src/ReactFiberHydrationContext.js index 8960419b80163..bd598d86dffdd 100644 --- a/packages/react-reconciler/src/ReactFiberHydrationContext.js +++ b/packages/react-reconciler/src/ReactFiberHydrationContext.js @@ -8,7 +8,6 @@ */ import type {Fiber} from './ReactInternalTypes'; -import {NoMode, ConcurrentMode} from './ReactTypeOfMode'; import type { Instance, TextInstance, @@ -28,19 +27,9 @@ import { HostRoot, SuspenseComponent, } from './ReactWorkTags'; -import { - ChildDeletion, - Placement, - Hydrating, - NoFlags, - DidCapture, -} from './ReactFiberFlags'; import {enableClientRenderFallbackOnTextMismatch} from 'shared/ReactFeatureFlags'; -import { - createFiberFromHostInstanceForDeletion, - createFiberFromDehydratedFragment, -} from './ReactFiber'; +import {createFiberFromDehydratedFragment} from './ReactFiber'; import { shouldSetTextContent, supportsHydration, @@ -176,14 +165,11 @@ function warnUnhydratedInstance( } case HostSingleton: case HostComponent: { - const isConcurrentMode = (returnFiber.mode & ConcurrentMode) !== NoMode; didNotHydrateInstance( returnFiber.type, returnFiber.memoizedProps, returnFiber.stateNode, instance, - // TODO: Delete this argument when we remove the legacy root API. - isConcurrentMode, ); break; } @@ -200,23 +186,6 @@ function warnUnhydratedInstance( } } -function deleteHydratableInstance( - returnFiber: Fiber, - instance: HydratableInstance, -) { - const childToDelete = createFiberFromHostInstanceForDeletion(); - childToDelete.stateNode = instance; - childToDelete.return = returnFiber; - - const deletions = returnFiber.deletions; - if (deletions === null) { - returnFiber.deletions = [childToDelete]; - returnFiber.flags |= ChildDeletion; - } else { - deletions.push(childToDelete); - } -} - function warnNonHydratedInstance(returnFiber: Fiber, fiber: Fiber) { if (__DEV__) { if (didSuspendOrErrorDEV) { @@ -265,30 +234,22 @@ function warnNonHydratedInstance(returnFiber: Fiber, fiber: Fiber) { case HostComponent: { const type = fiber.type; const props = fiber.pendingProps; - const isConcurrentMode = - (returnFiber.mode & ConcurrentMode) !== NoMode; didNotFindHydratableInstance( parentType, parentProps, parentInstance, type, props, - // TODO: Delete this argument when we remove the legacy root API. - isConcurrentMode, ); break; } case HostText: { const text = fiber.pendingProps; - const isConcurrentMode = - (returnFiber.mode & ConcurrentMode) !== NoMode; didNotFindHydratableTextInstance( parentType, parentProps, parentInstance, text, - // TODO: Delete this argument when we remove the legacy root API. - isConcurrentMode, ); break; } @@ -338,9 +299,6 @@ function warnNonHydratedInstance(returnFiber: Fiber, fiber: Fiber) { } } } -function insertNonHydratedInstance(returnFiber: Fiber, fiber: Fiber) { - fiber.flags = (fiber.flags & ~Hydrating) | Placement; -} function tryHydrateInstance(fiber: Fiber, nextInstance: any) { // fiber is a HostComponent Fiber @@ -408,13 +366,6 @@ function tryHydrateSuspense(fiber: Fiber, nextInstance: any) { return false; } -function shouldClientRenderOnMismatch(fiber: Fiber) { - return ( - (fiber.mode & ConcurrentMode) !== NoMode && - (fiber.flags & DidCapture) === NoFlags - ); -} - function throwOnHydrationMismatch(fiber: Fiber) { throw new Error( 'Hydration failed because the initial UI does not match what was ' + @@ -455,60 +406,18 @@ function tryToClaimNextHydratableInstance(fiber: Fiber): void { currentHostContext, ); - const initialInstance = nextHydratableInstance; const nextInstance = nextHydratableInstance; if (!nextInstance) { - if (shouldClientRenderOnMismatch(fiber)) { - if (shouldKeepWarning) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - } - throwOnHydrationMismatch(fiber); - } - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance((hydrationParentFiber: any), fiber); if (shouldKeepWarning) { warnNonHydratedInstance((hydrationParentFiber: any), fiber); } - isHydrating = false; - hydrationParentFiber = fiber; - nextHydratableInstance = initialInstance; - return; + throwOnHydrationMismatch(fiber); } - const firstAttemptedInstance = nextInstance; if (!tryHydrateInstance(fiber, nextInstance)) { - if (shouldClientRenderOnMismatch(fiber)) { - if (shouldKeepWarning) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - } - throwOnHydrationMismatch(fiber); - } - // If we can't hydrate this instance let's try the next one. - // We use this as a heuristic. It's based on intuition and not data so it - // might be flawed or unnecessary. - nextHydratableInstance = getNextHydratableSibling(nextInstance); - const prevHydrationParentFiber: Fiber = (hydrationParentFiber: any); - if ( - !nextHydratableInstance || - !tryHydrateInstance(fiber, nextHydratableInstance) - ) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance((hydrationParentFiber: any), fiber); - if (shouldKeepWarning) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - } - isHydrating = false; - hydrationParentFiber = fiber; - nextHydratableInstance = initialInstance; - return; - } - // We matched the next one, we'll now assume that the first one was - // superfluous and we'll delete it. Since we can't eagerly delete it - // we'll have to schedule a deletion. To do that, this node needs a dummy - // fiber associated with it. if (shouldKeepWarning) { - warnUnhydratedInstance(prevHydrationParentFiber, firstAttemptedInstance); + warnNonHydratedInstance((hydrationParentFiber: any), fiber); } - deleteHydratableInstance(prevHydrationParentFiber, firstAttemptedInstance); + throwOnHydrationMismatch(fiber); } } @@ -529,63 +438,20 @@ function tryToClaimNextHydratableTextInstance(fiber: Fiber): void { ); } - const initialInstance = nextHydratableInstance; const nextInstance = nextHydratableInstance; if (!nextInstance || !isHydratable) { // We exclude non hydrabable text because we know there are no matching hydratables. // We either throw or insert depending on the render mode. - if (shouldClientRenderOnMismatch(fiber)) { - if (shouldKeepWarning) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - } - throwOnHydrationMismatch(fiber); - } - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance((hydrationParentFiber: any), fiber); if (shouldKeepWarning) { warnNonHydratedInstance((hydrationParentFiber: any), fiber); } - isHydrating = false; - hydrationParentFiber = fiber; - nextHydratableInstance = initialInstance; - return; + throwOnHydrationMismatch(fiber); } - const firstAttemptedInstance = nextInstance; if (!tryHydrateText(fiber, nextInstance)) { - if (shouldClientRenderOnMismatch(fiber)) { - if (shouldKeepWarning) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - } - throwOnHydrationMismatch(fiber); - } - // If we can't hydrate this instance let's try the next one. - // We use this as a heuristic. It's based on intuition and not data so it - // might be flawed or unnecessary. - nextHydratableInstance = getNextHydratableSibling(nextInstance); - const prevHydrationParentFiber: Fiber = (hydrationParentFiber: any); - - if ( - !nextHydratableInstance || - !tryHydrateText(fiber, nextHydratableInstance) - ) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance((hydrationParentFiber: any), fiber); - if (shouldKeepWarning) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - } - isHydrating = false; - hydrationParentFiber = fiber; - nextHydratableInstance = initialInstance; - return; - } - // We matched the next one, we'll now assume that the first one was - // superfluous and we'll delete it. Since we can't eagerly delete it - // we'll have to schedule a deletion. To do that, this node needs a dummy - // fiber associated with it. if (shouldKeepWarning) { - warnUnhydratedInstance(prevHydrationParentFiber, firstAttemptedInstance); + warnNonHydratedInstance((hydrationParentFiber: any), fiber); } - deleteHydratableInstance(prevHydrationParentFiber, firstAttemptedInstance); + throwOnHydrationMismatch(fiber); } } @@ -593,51 +459,14 @@ function tryToClaimNextHydratableSuspenseInstance(fiber: Fiber): void { if (!isHydrating) { return; } - const initialInstance = nextHydratableInstance; const nextInstance = nextHydratableInstance; if (!nextInstance) { - if (shouldClientRenderOnMismatch(fiber)) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - throwOnHydrationMismatch(fiber); - } - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance((hydrationParentFiber: any), fiber); warnNonHydratedInstance((hydrationParentFiber: any), fiber); - isHydrating = false; - hydrationParentFiber = fiber; - nextHydratableInstance = initialInstance; - return; + throwOnHydrationMismatch(fiber); } - const firstAttemptedInstance = nextInstance; if (!tryHydrateSuspense(fiber, nextInstance)) { - if (shouldClientRenderOnMismatch(fiber)) { - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - throwOnHydrationMismatch(fiber); - } - // If we can't hydrate this instance let's try the next one. - // We use this as a heuristic. It's based on intuition and not data so it - // might be flawed or unnecessary. - nextHydratableInstance = getNextHydratableSibling(nextInstance); - const prevHydrationParentFiber: Fiber = (hydrationParentFiber: any); - - if ( - !nextHydratableInstance || - !tryHydrateSuspense(fiber, nextHydratableInstance) - ) { - // Nothing to hydrate. Make it an insertion. - insertNonHydratedInstance((hydrationParentFiber: any), fiber); - warnNonHydratedInstance((hydrationParentFiber: any), fiber); - isHydrating = false; - hydrationParentFiber = fiber; - nextHydratableInstance = initialInstance; - return; - } - // We matched the next one, we'll now assume that the first one was - // superfluous and we'll delete it. Since we can't eagerly delete it - // we'll have to schedule a deletion. To do that, this node needs a dummy - // fiber associated with it. - warnUnhydratedInstance(prevHydrationParentFiber, firstAttemptedInstance); - deleteHydratableInstance(prevHydrationParentFiber, firstAttemptedInstance); + warnNonHydratedInstance((hydrationParentFiber: any), fiber); + throwOnHydrationMismatch(fiber); } } @@ -717,17 +546,13 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean { switch (returnFiber.tag) { case HostRoot: { const parentContainer = returnFiber.stateNode.containerInfo; - const isConcurrentMode = - (returnFiber.mode & ConcurrentMode) !== NoMode; didNotMatchHydratedContainerTextInstance( parentContainer, textInstance, textContent, - // TODO: Delete this argument when we remove the legacy root API. - isConcurrentMode, shouldWarnIfMismatchDev, ); - if (isConcurrentMode && enableClientRenderFallbackOnTextMismatch) { + if (enableClientRenderFallbackOnTextMismatch) { // In concurrent mode we never update the mismatched text, // even if the error was ignored. return false; @@ -739,19 +564,15 @@ function prepareToHydrateHostTextInstance(fiber: Fiber): boolean { const parentType = returnFiber.type; const parentProps = returnFiber.memoizedProps; const parentInstance = returnFiber.stateNode; - const isConcurrentMode = - (returnFiber.mode & ConcurrentMode) !== NoMode; didNotMatchHydratedTextInstance( parentType, parentProps, parentInstance, textInstance, textContent, - // TODO: Delete this argument when we remove the legacy root API. - isConcurrentMode, shouldWarnIfMismatchDev, ); - if (isConcurrentMode && enableClientRenderFallbackOnTextMismatch) { + if (enableClientRenderFallbackOnTextMismatch) { // In concurrent mode we never update the mismatched text, // even if the error was ignored. return false; @@ -875,18 +696,10 @@ function popHydrationState(fiber: Fiber): boolean { } } if (shouldClear) { - let nextInstance = nextHydratableInstance; + const nextInstance = nextHydratableInstance; if (nextInstance) { - if (shouldClientRenderOnMismatch(fiber)) { - warnIfUnhydratedTailNodes(fiber); - throwOnHydrationMismatch(fiber); - } else { - while (nextInstance) { - warnUnhydratedInstance(fiber, nextInstance); - deleteHydratableInstance(fiber, nextInstance); - nextInstance = getNextHydratableSibling(nextInstance); - } - } + warnIfUnhydratedTailNodes(fiber); + throwOnHydrationMismatch(fiber); } } popToNextHostParent(fiber);