MCPcopy Create free account
hub / github.com/reactjs/react-rails / getValueForProperty

Function getValueForProperty

lib/assets/react-source/development/react.js:4876–4939  ·  view source on GitHub ↗

* Get the value for a property on a node. Only used in DEV for SSR validation. * The "expected" argument is used as a hint of what the expected value is. * Some properties have multiple equivalent values.

(node, name, expected, propertyInfo)

Source from the content-addressed store, hash-verified

4874 * Some properties have multiple equivalent values.
4875 */
4876 function getValueForProperty(node, name, expected, propertyInfo) {
4877 {
4878 if (propertyInfo.mustUseProperty) {
4879 var propertyName = propertyInfo.propertyName;
4880 return node[propertyName];
4881 } else {
4882 if ( propertyInfo.sanitizeURL) {
4883 // If we haven't fully disabled javascript: URLs, and if
4884 // the hydration is successful of a javascript: URL, we
4885 // still want to warn on the client.
4886 sanitizeURL('' + expected);
4887 }
4888
4889 var attributeName = propertyInfo.attributeName;
4890 var stringValue = null;
4891
4892 if (propertyInfo.type === OVERLOADED_BOOLEAN) {
4893 if (node.hasAttribute(attributeName)) {
4894 var value = node.getAttribute(attributeName);
4895
4896 if (value === '') {
4897 return true;
4898 }
4899
4900 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4901 return value;
4902 }
4903
4904 if (value === '' + expected) {
4905 return expected;
4906 }
4907
4908 return value;
4909 }
4910 } else if (node.hasAttribute(attributeName)) {
4911 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4912 // We had an attribute but shouldn't have had one, so read it
4913 // for the error message.
4914 return node.getAttribute(attributeName);
4915 }
4916
4917 if (propertyInfo.type === BOOLEAN) {
4918 // If this was a boolean, it doesn't matter what the value is
4919 // the fact that we have it is the same as the expected.
4920 return expected;
4921 } // Even if this property uses a namespace we use getAttribute
4922 // because we assume its namespaced name is the same as our config.
4923 // To use getAttributeNS we need the local name which we don't have
4924 // in our config atm.
4925
4926
4927 stringValue = node.getAttribute(attributeName);
4928 }
4929
4930 if (shouldRemoveAttribute(name, expected, propertyInfo, false)) {
4931 return stringValue === null ? expected : stringValue;
4932 } else if (stringValue === '' + expected) {
4933 return expected;

Callers 1

diffHydratedPropertiesFunction · 0.85

Calls 2

sanitizeURLFunction · 0.70
shouldRemoveAttributeFunction · 0.70

Tested by

no test coverage detected