Skip to content

Commit

Permalink
Clean up empty string special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Mar 1, 2024
1 parent b8da12e commit c62bed8
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 24 deletions.
7 changes: 0 additions & 7 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2977,13 +2977,6 @@ export function warnForInsertedHydratedText(
text: string,
) {
if (__DEV__) {
if (text === '') {
// We expect to insert empty text nodes since they're not represented in
// the HTML.
// TODO: Remove this special case if we can just avoid inserting empty
// text nodes.
return;
}
if (didWarnInvalidHydration) {
return;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1026,10 +1026,6 @@ export function bindInstance(

export const supportsHydration = true;

export function isHydratableText(text: string): boolean {
return text !== '';
}

export function canHydrateInstance(
instance: HydratableInstance,
type: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function shim(...args: any): empty {
// Hydration (when unsupported)
export type SuspenseInstance = mixed;
export const supportsHydration = false;
export const isHydratableText = shim;
export const isSuspenseInstancePending = shim;
export const isSuspenseInstanceFallback = shim;
export const getSuspenseInstanceFallbackErrorDetails = shim;
Expand Down
15 changes: 4 additions & 11 deletions packages/react-reconciler/src/ReactFiberHydrationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import {
canHydrateSuspenseInstance,
canHydrateFormStateMarker,
isFormStateMarkerMatching,
isHydratableText,
validateHydratableInstance,
validateHydratableTextInstance,
} from './ReactFiberConfig';
Expand Down Expand Up @@ -517,21 +516,15 @@ function tryToClaimNextHydratableTextInstance(fiber: Fiber): void {
return;
}
const text = fiber.pendingProps;
const isHydratable = isHydratableText(text);

let shouldKeepWarning = true;
if (isHydratable) {
// Validate that this is ok to render here before any mismatches.
const currentHostContext = getHostContext();
shouldKeepWarning = validateHydratableTextInstance(
text,
currentHostContext,
);
}
// Validate that this is ok to render here before any mismatches.
const currentHostContext = getHostContext();
shouldKeepWarning = validateHydratableTextInstance(text, currentHostContext);

const initialInstance = nextHydratableInstance;
const nextInstance = nextHydratableInstance;
if (!nextInstance || !isHydratable) {
if (!nextInstance) {
// 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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ export const cloneHiddenTextInstance = $$$config.cloneHiddenTextInstance;
// Hydration
// (optional)
// -------------------
export const isHydratableText = $$$config.isHydratableText;
export const isSuspenseInstancePending = $$$config.isSuspenseInstancePending;
export const isSuspenseInstanceFallback = $$$config.isSuspenseInstanceFallback;
export const getSuspenseInstanceFallbackErrorDetails =
Expand Down

0 comments on commit c62bed8

Please sign in to comment.