Commit 70fce26
committed
Fix input tracking bug
In 2019ddc, we changed to set .defaultValue before .value on updates. In some cases, setting .defaultValue causes .value to change, and since we only set .value if it has the wrong value, this resulted in us not assigning to .value, which resulted in inputValueTracking not knowing the right value. See new test added.
My fix here is to (a) move the value setting back up first and (b) narrowing the fix in the aforementioned PR to newly remove the value attribute only if it defaultValue was previously present in props.
The second half is necessary because for types where the value property and attribute are indelibly linked (hidden checkbox radio submit image reset button, i.e. spec modes default or default/on from https://html.spec.whatwg.org/multipage/input.html#dom-input-value-default), we can't remove the value attribute after setting .value, because that will undo the assignment we just did! That is, not having (b) makes all of those types fail to handle updating props.value.
This code is incredibly hard to think about but I think this is right (or at least, as right as the old code was) because we set .value here only if the nextProps.value != null, and we now remove defaultValue only if lastProps.defaultValue != null. These can't happen at the same time because we have long warned if value and defaultValue are simultaneously specified, and also if a component switches between controlled and uncontrolled.
Also, it fixes the test in #26626.1 parent d121c67 commit 70fce26
File tree
4 files changed
+82
-38
lines changed- packages
- react-dom-bindings/src/client
- react-dom/src/__tests__
4 files changed
+82
-38
lines changedLines changed: 19 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1297 | 1297 | | |
1298 | 1298 | | |
1299 | 1299 | | |
| 1300 | + | |
1300 | 1301 | | |
1301 | 1302 | | |
1302 | 1303 | | |
1303 | 1304 | | |
1304 | | - | |
1305 | | - | |
1306 | | - | |
1307 | | - | |
1308 | | - | |
| 1305 | + | |
1309 | 1306 | | |
1310 | 1307 | | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | | - | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
1317 | 1316 | | |
1318 | 1317 | | |
1319 | 1318 | | |
1320 | 1319 | | |
1321 | 1320 | | |
1322 | 1321 | | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
1323 | 1325 | | |
| 1326 | + | |
1324 | 1327 | | |
1325 | | - | |
| 1328 | + | |
| 1329 | + | |
1326 | 1330 | | |
1327 | 1331 | | |
1328 | 1332 | | |
| |||
1473 | 1477 | | |
1474 | 1478 | | |
1475 | 1479 | | |
| 1480 | + | |
1476 | 1481 | | |
1477 | 1482 | | |
1478 | 1483 | | |
| |||
1809 | 1814 | | |
1810 | 1815 | | |
1811 | 1816 | | |
| 1817 | + | |
1812 | 1818 | | |
1813 | 1819 | | |
1814 | 1820 | | |
| |||
1934 | 1940 | | |
1935 | 1941 | | |
1936 | 1942 | | |
| 1943 | + | |
1937 | 1944 | | |
1938 | 1945 | | |
1939 | 1946 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
88 | 89 | | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
94 | 116 | | |
95 | 117 | | |
96 | 118 | | |
97 | 119 | | |
98 | 120 | | |
99 | 121 | | |
100 | | - | |
| 122 | + | |
101 | 123 | | |
102 | 124 | | |
103 | 125 | | |
| |||
110 | 132 | | |
111 | 133 | | |
112 | 134 | | |
113 | | - | |
| 135 | + | |
114 | 136 | | |
115 | 137 | | |
116 | 138 | | |
| |||
135 | 157 | | |
136 | 158 | | |
137 | 159 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | 160 | | |
160 | 161 | | |
161 | 162 | | |
| |||
286 | 287 | | |
287 | 288 | | |
288 | 289 | | |
| 290 | + | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| |||
341 | 343 | | |
342 | 344 | | |
343 | 345 | | |
| 346 | + | |
344 | 347 | | |
345 | 348 | | |
346 | 349 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1166 | 1166 | | |
1167 | 1167 | | |
1168 | 1168 | | |
1169 | | - | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
1170 | 1174 | | |
1171 | 1175 | | |
1172 | 1176 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1952 | 1952 | | |
1953 | 1953 | | |
1954 | 1954 | | |
1955 | | - | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
1956 | 1960 | | |
1957 | 1961 | | |
1958 | 1962 | | |
| |||
1998 | 2002 | | |
1999 | 2003 | | |
2000 | 2004 | | |
2001 | | - | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
2002 | 2010 | | |
2003 | 2011 | | |
2004 | 2012 | | |
| |||
2183 | 2191 | | |
2184 | 2192 | | |
2185 | 2193 | | |
| 2194 | + | |
| 2195 | + | |
| 2196 | + | |
| 2197 | + | |
| 2198 | + | |
| 2199 | + | |
| 2200 | + | |
| 2201 | + | |
| 2202 | + | |
| 2203 | + | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
| 2208 | + | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
2186 | 2216 | | |
0 commit comments