Skip to content

Commit 9d9f12f

Browse files
committed
fixes
1 parent 2ed94f4 commit 9d9f12f

File tree

2 files changed

+41
-44
lines changed

2 files changed

+41
-44
lines changed

packages/react-dom-bindings/src/client/ReactDOMComponent.js

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,43 +2485,41 @@ function diffHydratedGenericElement(
24852485
case 'src':
24862486
case 'href':
24872487
if (
2488+
__DEV__ &&
24882489
value === '' &&
24892490
// <a href=""> is fine for "reload" links.
24902491
!(tag === 'a' && propKey === 'href') &&
24912492
!(tag === 'object' && propKey === 'data')
24922493
) {
2493-
if (__DEV__) {
2494-
if (propKey === 'src') {
2495-
console.error(
2496-
'An empty string ("") was passed to the %s attribute. ' +
2497-
'This may cause the browser to download the whole page again over the network. ' +
2498-
'To fix this, either do not render the element at all ' +
2499-
'or pass null to %s instead of an empty string.',
2500-
propKey,
2501-
propKey,
2502-
);
2503-
} else {
2504-
console.error(
2505-
'An empty string ("") was passed to the %s attribute. ' +
2506-
'To fix this, either do not render the element at all ' +
2507-
'or pass null to %s instead of an empty string.',
2508-
propKey,
2509-
propKey,
2510-
);
2511-
}
2512-
continue;
2494+
if (propKey === 'src') {
2495+
console.error(
2496+
'An empty string ("") was passed to the %s attribute. ' +
2497+
'This may cause the browser to download the whole page again over the network. ' +
2498+
'To fix this, either do not render the element at all ' +
2499+
'or pass null to %s instead of an empty string.',
2500+
propKey,
2501+
propKey,
2502+
);
2503+
} else {
2504+
console.error(
2505+
'An empty string ("") was passed to the %s attribute. ' +
2506+
'To fix this, either do not render the element at all ' +
2507+
'or pass null to %s instead of an empty string.',
2508+
propKey,
2509+
propKey,
2510+
);
25132511
}
2514-
} else {
2515-
hydrateSanitizedAttribute(
2516-
domElement,
2517-
propKey,
2518-
propKey,
2519-
value,
2520-
extraAttributes,
2521-
serverDifferences,
2522-
);
25232512
continue;
25242513
}
2514+
hydrateSanitizedAttribute(
2515+
domElement,
2516+
propKey,
2517+
propKey,
2518+
value,
2519+
extraAttributes,
2520+
serverDifferences,
2521+
);
2522+
continue;
25252523
case 'action':
25262524
case 'formAction': {
25272525
const serverValue = domElement.getAttribute(propKey);

packages/react-dom/src/__tests__/ReactDOMServerIntegrationAttributes-test.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,21 @@ describe('ReactDOMServerIntegration', () => {
6262
expect(e.getAttribute('href')).toBe('');
6363
});
6464

65-
describe.only('test', () => {
66-
itRenders('empty href on other tags', async render => {
67-
const e = await render(
68-
// <link href="" /> would be more sensible.
69-
// However, that results in a hydration warning as well.
70-
// Our test helpers do not support different error counts for initial
71-
// server render and hydration.
72-
// The number of errors on the server need to be equal to the number of
73-
// errors during hydration.
74-
// So we use a <div> instead.
75-
<div href="" />,
76-
1,
77-
);
78-
expect(e.getAttribute('href')).toBe(null);
79-
});
65+
itRenders('empty href on other tags', async render => {
66+
const e = await render(
67+
// <link href="" /> would be more sensible.
68+
// However, that results in a hydration warning as well.
69+
// Our test helpers do not support different error counts for initial
70+
// server render and hydration.
71+
// The number of errors on the server need to be equal to the number of
72+
// errors during hydration.
73+
// So we use a <div> instead.
74+
<div href="" />,
75+
1,
76+
);
77+
expect(e.getAttribute('href')).toBe(null);
8078
});
79+
8180
itRenders('no string prop with true value', async render => {
8281
const e = await render(<a href={true} />, 1);
8382
expect(e.hasAttribute('href')).toBe(false);

0 commit comments

Comments
 (0)