Skip to content

Commit

Permalink
Less hacky, more verbose, more runtime impact
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Silbermann committed Jan 6, 2024
1 parent 09191f6 commit 133867b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 27 deletions.
40 changes: 24 additions & 16 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ function setProp(
case 'disableRemotePlayback':
case 'formNoValidate':
case 'hidden':
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
case 'inert':
case 'loop':
case 'noModule':
case 'noValidate':
Expand All @@ -724,14 +724,18 @@ function setProp(
case 'scoped':
case 'seamless':
case 'itemScope': {
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
domElement.setAttribute(key, '');
} else {
domElement.removeAttribute(key);
const isNewBooleanProp = key === 'inert';
if (enableNewBooleanProps || !isNewBooleanProp) {
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
domElement.setAttribute(key, '');
} else {
domElement.removeAttribute(key);
}
break;
}
break;
}
// Overloaded Boolean
// eslint-disable-next-line no-fallthrough -- Re-enable once enableNewBooleanProps is removed.
case 'capture':
case 'download': {
// An attribute that can be used as a flag as well as with a value.
Expand Down Expand Up @@ -2487,7 +2491,7 @@ function diffHydratedGenericElement(
case 'disableRemotePlayback':
case 'formNoValidate':
case 'hidden':
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
case 'inert':
case 'loop':
case 'noModule':
case 'noValidate':
Expand All @@ -2499,16 +2503,20 @@ function diffHydratedGenericElement(
case 'scoped':
case 'seamless':
case 'itemScope': {
// Some of these need to be lower case to remove them from the extraAttributes list.
hydrateBooleanAttribute(
domElement,
propKey,
propKey.toLowerCase(),
value,
extraAttributes,
);
continue;
const isNewBooleanProp = propKey === 'inert';
if (enableNewBooleanProps || !isNewBooleanProp) {
// Some of these need to be lower case to remove them from the extraAttributes list.
hydrateBooleanAttribute(
domElement,
propKey,
propKey.toLowerCase(),
value,
extraAttributes,
);
continue;
}
}
// eslint-disable-next-line no-fallthrough -- Re-enable once enableNewBooleanProps is removed.
case 'capture':
case 'download': {
hydrateOverloadedBooleanAttribute(
Expand Down
22 changes: 13 additions & 9 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ function pushAttribute(
case 'disableRemotePlayback':
case 'formNoValidate':
case 'hidden':
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
case 'inert':
case 'loop':
case 'noModule':
case 'noValidate':
Expand All @@ -1307,16 +1307,20 @@ function pushAttribute(
case 'scoped':
case 'seamless':
case 'itemScope': {
// Boolean
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
target.push(
attributeSeparator,
stringToChunk(name),
attributeEmptyString,
);
const isNewBooleanProp = name === 'inert';
if (enableNewBooleanProps || !isNewBooleanProp) {
// Boolean
if (value && typeof value !== 'function' && typeof value !== 'symbol') {
target.push(
attributeSeparator,
stringToChunk(name),
attributeEmptyString,
);
}
return;
}
return;
}
// eslint-disable-next-line no-fallthrough -- Re-enable once enableNewBooleanProps is removed.
case 'capture':
case 'download': {
// Overloaded Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ function validateProperty(tagName, name, value, eventRegistry) {
case 'disableRemotePlayback':
case 'formNoValidate':
case 'hidden':
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
case 'loop':
case 'noModule':
case 'noValidate':
Expand All @@ -242,6 +241,10 @@ function validateProperty(tagName, name, value, eventRegistry) {
return true;
}
default: {
// TODO: Move into above cases once enableNewBooleanProps is removed.
if (enableNewBooleanProps && name === 'inert') {
return true;
}
const prefix = name.toLowerCase().slice(0, 5);
if (prefix === 'data-' || prefix === 'aria-') {
return true;
Expand Down Expand Up @@ -302,7 +305,6 @@ function validateProperty(tagName, name, value, eventRegistry) {
case 'disableRemotePlayback':
case 'formNoValidate':
case 'hidden':
case enableNewBooleanProps ? 'inert' : 'formNoValidate':
case 'loop':
case 'noModule':
case 'noValidate':
Expand All @@ -316,6 +318,11 @@ function validateProperty(tagName, name, value, eventRegistry) {
case 'itemScope': {
break;
}
case 'inert':
if (enableNewBooleanProps) {
break;
}
// eslint-disable-next-line no-fallthrough -- not flagged after DCE
default: {
return true;
}
Expand Down

0 comments on commit 133867b

Please sign in to comment.