Skip to content

Commit 4996a8f

Browse files
authored
Remove enableFilterEmptyStringAttributesDOM (#31765)
Base off #31764 This has landed everywhere
1 parent 3ad17ec commit 4996a8f

12 files changed

+209
-249
lines changed

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

Lines changed: 69 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ import {validateProperties as validateInputProperties} from '../shared/ReactDOMN
6363
import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';
6464
import sanitizeURL from '../shared/sanitizeURL';
6565

66-
import {
67-
enableTrustedTypesIntegration,
68-
enableFilterEmptyStringAttributesDOM,
69-
} from 'shared/ReactFeatureFlags';
66+
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
7067
import {
7168
mediaEventTypes,
7269
listenToNonDelegatedEvent,
@@ -400,35 +397,33 @@ function setProp(
400397
// fallthrough
401398
case 'src':
402399
case 'href': {
403-
if (enableFilterEmptyStringAttributesDOM) {
404-
if (
405-
value === '' &&
406-
// <a href=""> is fine for "reload" links.
407-
!(tag === 'a' && key === 'href')
408-
) {
409-
if (__DEV__) {
410-
if (key === 'src') {
411-
console.error(
412-
'An empty string ("") was passed to the %s attribute. ' +
413-
'This may cause the browser to download the whole page again over the network. ' +
414-
'To fix this, either do not render the element at all ' +
415-
'or pass null to %s instead of an empty string.',
416-
key,
417-
key,
418-
);
419-
} else {
420-
console.error(
421-
'An empty string ("") was passed to the %s attribute. ' +
422-
'To fix this, either do not render the element at all ' +
423-
'or pass null to %s instead of an empty string.',
424-
key,
425-
key,
426-
);
427-
}
400+
if (
401+
value === '' &&
402+
// <a href=""> is fine for "reload" links.
403+
!(tag === 'a' && key === 'href')
404+
) {
405+
if (__DEV__) {
406+
if (key === 'src') {
407+
console.error(
408+
'An empty string ("") was passed to the %s attribute. ' +
409+
'This may cause the browser to download the whole page again over the network. ' +
410+
'To fix this, either do not render the element at all ' +
411+
'or pass null to %s instead of an empty string.',
412+
key,
413+
key,
414+
);
415+
} else {
416+
console.error(
417+
'An empty string ("") was passed to the %s attribute. ' +
418+
'To fix this, either do not render the element at all ' +
419+
'or pass null to %s instead of an empty string.',
420+
key,
421+
key,
422+
);
428423
}
429-
domElement.removeAttribute(key);
430-
break;
431424
}
425+
domElement.removeAttribute(key);
426+
break;
432427
}
433428
if (
434429
value == null ||
@@ -2489,53 +2484,52 @@ function diffHydratedGenericElement(
24892484
// fallthrough
24902485
case 'src':
24912486
case 'href':
2492-
if (enableFilterEmptyStringAttributesDOM) {
2493-
if (
2494-
value === '' &&
2495-
// <a href=""> is fine for "reload" links.
2496-
!(tag === 'a' && propKey === 'href') &&
2497-
!(tag === 'object' && propKey === 'data')
2498-
) {
2499-
if (__DEV__) {
2500-
if (propKey === 'src') {
2501-
console.error(
2502-
'An empty string ("") was passed to the %s attribute. ' +
2503-
'This may cause the browser to download the whole page again over the network. ' +
2504-
'To fix this, either do not render the element at all ' +
2505-
'or pass null to %s instead of an empty string.',
2506-
propKey,
2507-
propKey,
2508-
);
2509-
} else {
2510-
console.error(
2511-
'An empty string ("") was passed to the %s attribute. ' +
2512-
'To fix this, either do not render the element at all ' +
2513-
'or pass null to %s instead of an empty string.',
2514-
propKey,
2515-
propKey,
2516-
);
2517-
}
2487+
if (
2488+
value === '' &&
2489+
// <a href=""> is fine for "reload" links.
2490+
!(tag === 'a' && propKey === 'href') &&
2491+
!(tag === 'object' && propKey === 'data')
2492+
) {
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+
);
25182511
}
2519-
hydrateSanitizedAttribute(
2520-
domElement,
2521-
propKey,
2522-
propKey,
2523-
null,
2524-
extraAttributes,
2525-
serverDifferences,
2526-
);
2527-
continue;
25282512
}
2513+
hydrateSanitizedAttribute(
2514+
domElement,
2515+
propKey,
2516+
propKey,
2517+
null,
2518+
extraAttributes,
2519+
serverDifferences,
2520+
);
2521+
continue;
2522+
} else {
2523+
hydrateSanitizedAttribute(
2524+
domElement,
2525+
propKey,
2526+
propKey,
2527+
value,
2528+
extraAttributes,
2529+
serverDifferences,
2530+
);
2531+
continue;
25292532
}
2530-
hydrateSanitizedAttribute(
2531-
domElement,
2532-
propKey,
2533-
propKey,
2534-
value,
2535-
extraAttributes,
2536-
serverDifferences,
2537-
);
2538-
continue;
25392533
case 'action':
25402534
case 'formAction': {
25412535
const serverValue = domElement.getAttribute(propKey);

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 32 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ import {
2727

2828
import {Children} from 'react';
2929

30-
import {
31-
enableFilterEmptyStringAttributesDOM,
32-
enableFizzExternalRuntime,
33-
} from 'shared/ReactFeatureFlags';
30+
import {enableFizzExternalRuntime} from 'shared/ReactFeatureFlags';
3431

3532
import type {
3633
Destination,
@@ -1210,30 +1207,28 @@ function pushAttribute(
12101207
}
12111208
case 'src':
12121209
case 'href': {
1213-
if (enableFilterEmptyStringAttributesDOM) {
1214-
if (value === '') {
1215-
if (__DEV__) {
1216-
if (name === 'src') {
1217-
console.error(
1218-
'An empty string ("") was passed to the %s attribute. ' +
1219-
'This may cause the browser to download the whole page again over the network. ' +
1220-
'To fix this, either do not render the element at all ' +
1221-
'or pass null to %s instead of an empty string.',
1222-
name,
1223-
name,
1224-
);
1225-
} else {
1226-
console.error(
1227-
'An empty string ("") was passed to the %s attribute. ' +
1228-
'To fix this, either do not render the element at all ' +
1229-
'or pass null to %s instead of an empty string.',
1230-
name,
1231-
name,
1232-
);
1233-
}
1210+
if (value === '') {
1211+
if (__DEV__) {
1212+
if (name === 'src') {
1213+
console.error(
1214+
'An empty string ("") was passed to the %s attribute. ' +
1215+
'This may cause the browser to download the whole page again over the network. ' +
1216+
'To fix this, either do not render the element at all ' +
1217+
'or pass null to %s instead of an empty string.',
1218+
name,
1219+
name,
1220+
);
1221+
} else {
1222+
console.error(
1223+
'An empty string ("") was passed to the %s attribute. ' +
1224+
'To fix this, either do not render the element at all ' +
1225+
'or pass null to %s instead of an empty string.',
1226+
name,
1227+
name,
1228+
);
12341229
}
1235-
return;
12361230
}
1231+
return;
12371232
}
12381233
}
12391234
// Fall through to the last case which shouldn't remove empty strings.
@@ -1633,19 +1628,17 @@ function pushStartObject(
16331628
checkAttributeStringCoercion(propValue, 'data');
16341629
}
16351630
const sanitizedValue = sanitizeURL('' + propValue);
1636-
if (enableFilterEmptyStringAttributesDOM) {
1637-
if (sanitizedValue === '') {
1638-
if (__DEV__) {
1639-
console.error(
1640-
'An empty string ("") was passed to the %s attribute. ' +
1641-
'To fix this, either do not render the element at all ' +
1642-
'or pass null to %s instead of an empty string.',
1643-
propKey,
1644-
propKey,
1645-
);
1646-
}
1647-
break;
1631+
if (sanitizedValue === '') {
1632+
if (__DEV__) {
1633+
console.error(
1634+
'An empty string ("") was passed to the %s attribute. ' +
1635+
'To fix this, either do not render the element at all ' +
1636+
'or pass null to %s instead of an empty string.',
1637+
propKey,
1638+
propKey,
1639+
);
16481640
}
1641+
break;
16491642
}
16501643
target.push(
16511644
attributeSeparator,
@@ -3615,11 +3608,7 @@ export function pushStartInstance(
36153608
// Fast track very common tags
36163609
break;
36173610
case 'a':
3618-
if (enableFilterEmptyStringAttributesDOM) {
3619-
return pushStartAnchor(target, props);
3620-
} else {
3621-
break;
3622-
}
3611+
return pushStartAnchor(target, props);
36233612
case 'g':
36243613
case 'p':
36253614
case 'li':

0 commit comments

Comments
 (0)