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

Clean up empty string special cases #28475

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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