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

[fizz] fix empty string href double warning #31783

Merged
merged 7 commits into from
Jan 3, 2025
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
27 changes: 9 additions & 18 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2510,26 +2510,17 @@ function diffHydratedGenericElement(
);
}
}
hydrateSanitizedAttribute(
domElement,
propKey,
propKey,
null,
extraAttributes,
serverDifferences,
);
continue;
} else {
hydrateSanitizedAttribute(
domElement,
propKey,
propKey,
value,
extraAttributes,
serverDifferences,
);
continue;
}
hydrateSanitizedAttribute(
domElement,
propKey,
propKey,
value,
extraAttributes,
serverDifferences,
);
continue;
case 'action':
case 'formAction': {
const serverValue = domElement.getAttribute(propKey);
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,9 @@ export function canHydrateInstance(
} else if (
rel !== anyProps.rel ||
element.getAttribute('href') !==
(anyProps.href == null ? null : anyProps.href) ||
(anyProps.href == null || anyProps.href === ''
? null
: anyProps.href) ||
element.getAttribute('crossorigin') !==
(anyProps.crossOrigin == null ? null : anyProps.crossOrigin) ||
element.getAttribute('title') !==
Expand Down Expand Up @@ -2984,7 +2986,7 @@ export function hydrateHoistable(
const node = nodes[i];
if (
node.getAttribute('href') !==
(props.href == null ? null : props.href) ||
(props.href == null || props.href === '' ? null : props.href) ||
node.getAttribute('rel') !==
(props.rel == null ? null : props.rel) ||
node.getAttribute('title') !==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,23 @@ describe('ReactDOMServerIntegration', () => {
expect(e.getAttribute('href')).toBe('');
});

itRenders('empty href on other tags', async render => {
itRenders('empty href on base tags as null', async render => {
const e = await render(<base href="" />, 1);
expect(e.getAttribute('href')).toBe(null);
});

itRenders('empty href on area tags as null', async render => {
const e = await render(
// <link href="" /> would be more sensible.
// However, that results in a hydration warning as well.
// Our test helpers do not support different error counts for initial
// server render and hydration.
// The number of errors on the server need to be equal to the number of
// errors during hydration.
// So we use a <div> instead.
<div href="" />,
<map>
<area alt="" href="" />
</map>,
1,
);
expect(e.firstChild.getAttribute('href')).toBe(null);
});

itRenders('empty href on link tags as null', async render => {
const e = await render(<link rel="stylesheet" href="" />, 1);
expect(e.getAttribute('href')).toBe(null);
});

Expand Down
Loading