MCPcopy Index your code
hub / github.com/microsoft/SandDance / postMountWrapper

Function postMountWrapper

docs/external/js/react-dom.development.js:2047–2110  ·  view source on GitHub ↗
(element, props, isHydrating)

Source from the content-addressed store, hash-verified

2045 }
2046 }
2047 function postMountWrapper(element, props, isHydrating) {
2048 var node = element; // Do not assign value if it is already set. This prevents user text input
2049 // from being lost during SSR hydration.
2050
2051 if (props.hasOwnProperty('value') || props.hasOwnProperty('defaultValue')) {
2052 var type = props.type;
2053 var isButton = type === 'submit' || type === 'reset'; // Avoid setting value attribute on submit/reset inputs as it overrides the
2054 // default value provided by the browser. See: #12872
2055
2056 if (isButton && (props.value === undefined || props.value === null)) {
2057 return;
2058 }
2059
2060 var initialValue = toString(node._wrapperState.initialValue); // Do not assign value if it is already set. This prevents user text input
2061 // from being lost during SSR hydration.
2062
2063 if (!isHydrating) {
2064 {
2065 // When syncing the value attribute, the value property should use
2066 // the wrapperState._initialValue property. This uses:
2067 //
2068 // 1. The value React property when present
2069 // 2. The defaultValue React property when present
2070 // 3. An empty string
2071 if (initialValue !== node.value) {
2072 node.value = initialValue;
2073 }
2074 }
2075 }
2076
2077 {
2078 // Otherwise, the value attribute is synchronized to the property,
2079 // so we assign defaultValue to the same thing as the value property
2080 // assignment step above.
2081 node.defaultValue = initialValue;
2082 }
2083 } // Normally, we'd just do `node.checked = node.checked` upon initial mount, less this bug
2084 // this is needed to work around a chrome bug where setting defaultChecked
2085 // will sometimes influence the value of checked (even after detachment).
2086 // Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=608416
2087 // We need to temporarily unset name to avoid disrupting radio button groups.
2088
2089
2090 var name = node.name;
2091
2092 if (name !== '') {
2093 node.name = '';
2094 }
2095
2096 {
2097 // When syncing the checked attribute, both the checked property and
2098 // attribute are assigned at the same time using defaultChecked. This uses:
2099 //
2100 // 1. The checked React property when present
2101 // 2. The defaultChecked React property when present
2102 // 3. Otherwise, false
2103 node.defaultChecked = !node.defaultChecked;
2104 node.defaultChecked = !!node._wrapperState.initialChecked;

Callers 2

setInitialPropertiesFunction · 0.85
diffHydratedPropertiesFunction · 0.85

Calls 1

toStringFunction · 0.70

Tested by

no test coverage detected