Skip to content

Commit a079011

Browse files
nhunzakergaearon
authored andcommitted
🔥 Stop syncing the value attribute on inputs (behind a feature flag) (#13526)
* 🔥 Stop syncing the value attribute on inputs * Eliminate some additional checks * Remove initialValue and initialWrapper from wrapperState flow type * Update tests with new sync logic, reduce some operations * Update tests, add some caveats for SSR mismatches * Revert newline change * Remove unused type * Call toString to safely type string values * Add disableInputAttributeSyncing feature flag Reverts tests to original state, adds attribute sync feature flag, then moves all affected tests to ReactFire-test.js. * Revert position of types in toStringValues * Invert flag on number input blur * Add clarification why double blur is necessary * Update ReactFire number cases to be more explicite about blur * Move comments to reduce diff size * Add comments to clarify behavior in each branch * There is no need to assign a different checked behavior in Fire * Use checked reference * Format * Avoid precomputing stringable values * Revert getToStringValue comment * Revert placement of undefined in getToStringValue * Do not eagerly stringify value * Unify Fire test cases with normal ones * Revert toString change. Only assign unsynced values when not nully
1 parent a7bd7c3 commit a079011

16 files changed

Lines changed: 360 additions & 84 deletions

‎packages/react-dom/src/__tests__/DOMPropertyOperations-test.js‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
'use strict';
1111

12+
// Set by `yarn test-fire`.
13+
const {disableInputAttributeSyncing} = require('shared/ReactFeatureFlags');
14+
1215
describe('DOMPropertyOperations', () => {
1316
let React;
1417
let ReactDOM;
@@ -80,7 +83,11 @@ describe('DOMPropertyOperations', () => {
8083
it('should not remove empty attributes for special input properties', () => {
8184
const container = document.createElement('div');
8285
ReactDOM.render(<input value="" onChange={() => {}} />, container);
83-
expect(container.firstChild.getAttribute('value')).toBe('');
86+
if (disableInputAttributeSyncing) {
87+
expect(container.firstChild.hasAttribute('value')).toBe(false);
88+
} else {
89+
expect(container.firstChild.getAttribute('value')).toBe('');
90+
}
8491
expect(container.firstChild.value).toBe('');
8592
});
8693

@@ -165,7 +172,11 @@ describe('DOMPropertyOperations', () => {
165172
<input type="text" value="foo" onChange={function() {}} />,
166173
container,
167174
);
168-
expect(container.firstChild.getAttribute('value')).toBe('foo');
175+
if (disableInputAttributeSyncing) {
176+
expect(container.firstChild.hasAttribute('value')).toBe(false);
177+
} else {
178+
expect(container.firstChild.getAttribute('value')).toBe('foo');
179+
}
169180
expect(container.firstChild.value).toBe('foo');
170181
expect(() =>
171182
ReactDOM.render(
@@ -175,7 +186,11 @@ describe('DOMPropertyOperations', () => {
175186
).toWarnDev(
176187
'A component is changing a controlled input of type text to be uncontrolled',
177188
);
178-
expect(container.firstChild.getAttribute('value')).toBe('foo');
189+
if (disableInputAttributeSyncing) {
190+
expect(container.firstChild.hasAttribute('value')).toBe(false);
191+
} else {
192+
expect(container.firstChild.getAttribute('value')).toBe('foo');
193+
}
179194
expect(container.firstChild.value).toBe('foo');
180195
});
181196

0 commit comments

Comments
 (0)