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

Land enableCustomElementPropertySupport for React 19 #27450

Merged
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
22 changes: 6 additions & 16 deletions packages/react-dom-bindings/src/client/DOMPropertyOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
*/

import isAttributeNameSafe from '../shared/isAttributeNameSafe';
import {
enableTrustedTypesIntegration,
enableCustomElementPropertySupport,
} from 'shared/ReactFeatureFlags';
import {enableTrustedTypesIntegration} from 'shared/ReactFeatureFlags';
import {checkAttributeStringCoercion} from 'shared/CheckStringCoercion';
import {getFiberCurrentPropsFromNode} from './ReactDOMComponentTree';

Expand Down Expand Up @@ -73,25 +70,18 @@ export function getValueForAttributeOnCustomComponent(
// it would be expected that they end up not having an attribute.
return expected;
case 'function':
if (enableCustomElementPropertySupport) {
return expected;
}
break;
return expected;
case 'boolean':
if (enableCustomElementPropertySupport) {
if (expected === false) {
return expected;
}
if (expected === false) {
return expected;
}
}
return expected === undefined ? undefined : null;
}
const value = node.getAttribute(name);

if (enableCustomElementPropertySupport) {
if (value === '' && expected === true) {
return true;
}
if (value === '' && expected === true) {
return true;
}

if (__DEV__) {
Expand Down
75 changes: 31 additions & 44 deletions packages/react-dom-bindings/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import sanitizeURL from '../shared/sanitizeURL';

import {
enableBigIntSupport,
enableCustomElementPropertySupport,
disableIEWorkarounds,
enableTrustedTypesIntegration,
enableFilterEmptyStringAttributesDOM,
Expand Down Expand Up @@ -870,9 +869,7 @@ function setProp(
}
case 'innerText':
case 'textContent':
if (enableCustomElementPropertySupport) {
break;
}
break;
// Fall through
default: {
if (
Expand Down Expand Up @@ -983,25 +980,15 @@ function setPropOnCustomElement(
}
case 'innerText': // Properties
case 'textContent':
if (enableCustomElementPropertySupport) {
break;
}
break;
// Fall through
default: {
if (registrationNameDependencies.hasOwnProperty(key)) {
if (__DEV__ && value != null && typeof value !== 'function') {
warnForInvalidEventListener(key, value);
}
} else {
if (enableCustomElementPropertySupport) {
setValueForPropertyOnCustomComponent(domElement, key, value);
} else {
if (typeof value === 'boolean') {
// Special case before the new flag is on
value = '' + (value: any);
}
setValueForAttribute(domElement, key, value);
}
setValueForPropertyOnCustomComponent(domElement, key, value);
}
}
}
Expand Down Expand Up @@ -2293,35 +2280,30 @@ function diffHydratedCustomComponent(
case 'isContentEditable':
case 'outerText':
case 'outerHTML':
if (enableCustomElementPropertySupport) {
extraAttributes.delete(propKey.toLowerCase());
if (__DEV__) {
console.error(
'Assignment to read-only property will result in a no-op: `%s`',
propKey,
);
}
continue;
}
// Fall through
case 'className':
if (enableCustomElementPropertySupport) {
// className is a special cased property on the server to render as an attribute.
extraAttributes.delete('class');
const serverValue = getValueForAttributeOnCustomComponent(
domElement,
'class',
value,
);
warnForPropDifference(
'className',
serverValue,
value,
serverDifferences,
extraAttributes.delete(propKey.toLowerCase());
if (__DEV__) {
console.error(
'Assignment to read-only property will result in a no-op: `%s`',
propKey,
);
continue;
}
continue;
// Fall through
rickhanlonii marked this conversation as resolved.
Show resolved Hide resolved
case 'className':
// className is a special cased property on the server to render as an attribute.
extraAttributes.delete('class');
const serverValue = getValueForAttributeOnCustomComponent(
domElement,
'class',
value,
);
warnForPropDifference(
'className',
serverValue,
value,
serverDifferences,
);
continue;
default: {
// This is a DEV-only path
const hostContextDev: HostContextDev = (hostContext: any);
Expand All @@ -2335,12 +2317,17 @@ function diffHydratedCustomComponent(
} else {
extraAttributes.delete(propKey);
}
const serverValue = getValueForAttributeOnCustomComponent(
const valueOnCustomComponent = getValueForAttributeOnCustomComponent(
domElement,
propKey,
value,
);
warnForPropDifference(propKey, serverValue, value, serverDifferences);
warnForPropDifference(
propKey,
valueOnCustomComponent,
value,
serverDifferences,
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ import {updateValueIfChanged} from '../../client/inputValueTracking';
import {setDefaultValue} from '../../client/ReactDOMInput';
import {enqueueStateRestore} from '../ReactDOMControlledComponent';

import {
disableInputAttributeSyncing,
enableCustomElementPropertySupport,
} from 'shared/ReactFeatureFlags';
import {disableInputAttributeSyncing} from 'shared/ReactFeatureFlags';
import {batchedUpdates} from '../ReactDOMUpdateBatching';
import {
processDispatchQueue,
Expand Down Expand Up @@ -311,7 +308,6 @@ function extractEvents(
} else if (shouldUseClickEvent(targetNode)) {
getTargetInstFunc = getTargetInstForClickEvent;
} else if (
enableCustomElementPropertySupport &&
targetInst &&
isCustomElement(targetInst.elementType, targetInst.memoizedProps)
) {
Expand Down
23 changes: 9 additions & 14 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import {Children} from 'react';
import {
enableBigIntSupport,
enableFilterEmptyStringAttributesDOM,
enableCustomElementPropertySupport,
enableFizzExternalRuntime,
enableNewBooleanProps,
} from 'shared/ReactFeatureFlags';
Expand Down Expand Up @@ -3342,26 +3341,22 @@ function pushStartCustomElement(
// Ignored. These are built-in to React on the client.
break;
case 'className':
if (enableCustomElementPropertySupport) {
// className gets rendered as class on the client, so it should be
// rendered as class on the server.
attributeName = 'class';
}
// className gets rendered as class on the client, so it should be
// rendered as class on the server.
attributeName = 'class';
// intentional fallthrough
default:
if (
isAttributeNameSafe(propKey) &&
typeof propValue !== 'function' &&
typeof propValue !== 'symbol'
) {
if (enableCustomElementPropertySupport) {
if (propValue === false) {
continue;
} else if (propValue === true) {
propValue = '';
} else if (typeof propValue === 'object') {
continue;
}
if (propValue === false) {
continue;
} else if (propValue === true) {
propValue = '';
} else if (typeof propValue === 'object') {
continue;
}
target.push(
attributeSeparator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {ATTRIBUTE_NAME_CHAR} from './isAttributeNameSafe';
import isCustomElement from './isCustomElement';
import possibleStandardNames from './possibleStandardNames';
import hasOwnProperty from 'shared/hasOwnProperty';
import {
enableCustomElementPropertySupport,
enableNewBooleanProps,
} from 'shared/ReactFeatureFlags';
import {enableNewBooleanProps} from 'shared/ReactFeatureFlags';

const warnedProperties = {};
const EVENT_NAME_REGEX = /^on./;
Expand Down Expand Up @@ -189,9 +186,7 @@ function validateProperty(tagName, name, value, eventRegistry) {
}
case 'innerText': // Properties
case 'textContent':
if (enableCustomElementPropertySupport) {
return true;
}
return true;
}

switch (typeof value) {
Expand Down
Loading