Skip to content

Commit 78391f0

Browse files
author
Sebastian Silbermann
committed
Less hacky, more verbose, more runtime impact
1 parent 78f1ad6 commit 78391f0

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ function setProp(
716716
case 'disableRemotePlayback':
717717
case 'formNoValidate':
718718
case 'hidden':
719-
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
719+
case 'inert':
720720
case 'loop':
721721
case 'noModule':
722722
case 'noValidate':
@@ -728,14 +728,18 @@ function setProp(
728728
case 'scoped':
729729
case 'seamless':
730730
case 'itemScope': {
731-
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
732-
domElement.setAttribute(key, '');
733-
} else {
734-
domElement.removeAttribute(key);
731+
const isNewBooleanProp = key === 'inert';
732+
if (enableNewBooleanProps || !isNewBooleanProp) {
733+
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
734+
domElement.setAttribute(key, '');
735+
} else {
736+
domElement.removeAttribute(key);
737+
}
738+
break;
735739
}
736-
break;
737740
}
738741
// Overloaded Boolean
742+
// eslint-disable-next-line no-fallthrough -- Re-enable once enableNewBooleanProps is removed.
739743
case 'capture':
740744
case 'download': {
741745
// An attribute that can be used as a flag as well as with a value.
@@ -2495,7 +2499,7 @@ function diffHydratedGenericElement(
24952499
case 'disableRemotePlayback':
24962500
case 'formNoValidate':
24972501
case 'hidden':
2498-
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
2502+
case 'inert':
24992503
case 'loop':
25002504
case 'noModule':
25012505
case 'noValidate':
@@ -2507,16 +2511,20 @@ function diffHydratedGenericElement(
25072511
case 'scoped':
25082512
case 'seamless':
25092513
case 'itemScope': {
2510-
// Some of these need to be lower case to remove them from the extraAttributes list.
2511-
hydrateBooleanAttribute(
2512-
domElement,
2513-
propKey,
2514-
propKey.toLowerCase(),
2515-
value,
2516-
extraAttributes,
2517-
);
2518-
continue;
2514+
const isNewBooleanProp = propKey === 'inert';
2515+
if (enableNewBooleanProps || !isNewBooleanProp) {
2516+
// Some of these need to be lower case to remove them from the extraAttributes list.
2517+
hydrateBooleanAttribute(
2518+
domElement,
2519+
propKey,
2520+
propKey.toLowerCase(),
2521+
value,
2522+
extraAttributes,
2523+
);
2524+
continue;
2525+
}
25192526
}
2527+
// eslint-disable-next-line no-fallthrough -- Re-enable once enableNewBooleanProps is removed.
25202528
case 'capture':
25212529
case 'download': {
25222530
hydrateOverloadedBooleanAttribute(

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ function pushAttribute(
12901290
case 'disableRemotePlayback':
12911291
case 'formNoValidate':
12921292
case 'hidden':
1293-
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
1293+
case 'inert':
12941294
case 'loop':
12951295
case 'noModule':
12961296
case 'noValidate':
@@ -1302,16 +1302,20 @@ function pushAttribute(
13021302
case 'scoped':
13031303
case 'seamless':
13041304
case 'itemScope': {
1305-
// Boolean
1306-
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
1307-
target.push(
1308-
attributeSeparator,
1309-
stringToChunk(name),
1310-
attributeEmptyString,
1311-
);
1305+
const isNewBooleanProp = name === 'inert';
1306+
if (enableNewBooleanProps || !isNewBooleanProp) {
1307+
// Boolean
1308+
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
1309+
target.push(
1310+
attributeSeparator,
1311+
stringToChunk(name),
1312+
attributeEmptyString,
1313+
);
1314+
}
1315+
return;
13121316
}
1313-
return;
13141317
}
1318+
// eslint-disable-next-line no-fallthrough -- Re-enable once enableNewBooleanProps is removed.
13151319
case 'capture':
13161320
case 'download': {
13171321
// Overloaded Boolean

packages/react-dom-bindings/src/shared/ReactDOMUnknownPropertyHook.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ function validateProperty(tagName, name, value, eventRegistry) {
224224
case 'disableRemotePlayback':
225225
case 'formNoValidate':
226226
case 'hidden':
227-
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
228227
case 'loop':
229228
case 'noModule':
230229
case 'noValidate':
@@ -242,6 +241,10 @@ function validateProperty(tagName, name, value, eventRegistry) {
242241
return true;
243242
}
244243
default: {
244+
// TODO: Move into above cases once enableNewBooleanProps is removed.
245+
if (enableNewBooleanProps && name === 'inert') {
246+
return true;
247+
}
245248
const prefix = name.toLowerCase().slice(0, 5);
246249
if (prefix === 'data-' || prefix === 'aria-') {
247250
return true;
@@ -302,7 +305,6 @@ function validateProperty(tagName, name, value, eventRegistry) {
302305
case 'disableRemotePlayback':
303306
case 'formNoValidate':
304307
case 'hidden':
305-
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
306308
case 'loop':
307309
case 'noModule':
308310
case 'noValidate':
@@ -316,6 +318,11 @@ function validateProperty(tagName, name, value, eventRegistry) {
316318
case 'itemScope': {
317319
break;
318320
}
321+
case 'inert':
322+
if (enableNewBooleanProps) {
323+
break;
324+
}
325+
// eslint-disable-next-line no-fallthrough -- not flagged after DCE
319326
default: {
320327
return true;
321328
}

0 commit comments

Comments
 (0)