Commit 9a2dba7
committed
Switching checked to null should leave the current value (#26667)
I accidentally made a behavior change in the refactor. It turns out that
when switching off `checked` to an uncontrolled component, we used to
revert to the concept of "initialChecked" which used to be stored on
state.
When there's a diff to this computed prop and the value of props.checked
is null, then we end up in a case where it sets `checked` to
`initialChecked`:
https://github.com/facebook/react/blob/5cbe6258bc436b1683080a6d978c27849f1d9a22/packages/react-dom-bindings/src/client/ReactDOMInput.js#L69
Since we never changed `initialChecked` and it's not relevant if
non-null `checked` changes value, the only way this "change" could
trigger was if we move from having `checked` to having null.
This wasn't really consistent with how `value` works, where we instead
leave the current value in place regardless. So this is a "bug fix" that
changes `checked` to be consistent with `value` and just leave the
current value in place. This case should already have a warning in it
regardless since it's going from controlled to uncontrolled.
Related to that, there was also another issue observed in
#26596 (comment) and
#26588
We need to atomically apply mutations on radio buttons. I fixed this by
setting the name to empty before doing mutations to value/checked/type
in updateInput, and then set the name to whatever it should be. Setting
the name is what ends up atomically applying the changes.
---------
Co-authored-by: Sophie Alpert <git@sophiebits.com>
DiffTrain build for commit 1f248bd.1 parent 5b6046d commit 9a2dba7
File tree
13 files changed
+19
-19
lines changed- compiled-rn/facebook-fbsource/xplat/js
- RKJSModules/vendor
- react-test-renderer/cjs
- react/cjs
- react-native-github/Libraries/Renderer
- implementations
13 files changed
+19
-19
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23745 | 23745 | | |
23746 | 23746 | | |
23747 | 23747 | | |
23748 | | - | |
| 23748 | + | |
23749 | 23749 | | |
23750 | 23750 | | |
23751 | 23751 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8587 | 8587 | | |
8588 | 8588 | | |
8589 | 8589 | | |
8590 | | - | |
| 8590 | + | |
8591 | 8591 | | |
8592 | 8592 | | |
8593 | 8593 | | |
| |||
8618 | 8618 | | |
8619 | 8619 | | |
8620 | 8620 | | |
8621 | | - | |
| 8621 | + | |
8622 | 8622 | | |
8623 | 8623 | | |
8624 | 8624 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9013 | 9013 | | |
9014 | 9014 | | |
9015 | 9015 | | |
9016 | | - | |
| 9016 | + | |
9017 | 9017 | | |
9018 | 9018 | | |
9019 | 9019 | | |
| |||
9044 | 9044 | | |
9045 | 9045 | | |
9046 | 9046 | | |
9047 | | - | |
| 9047 | + | |
9048 | 9048 | | |
9049 | 9049 | | |
9050 | 9050 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
642 | | - | |
| 642 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
645 | | - | |
| 645 | + | |
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27052 | 27052 | | |
27053 | 27053 | | |
27054 | 27054 | | |
27055 | | - | |
| 27055 | + | |
27056 | 27056 | | |
27057 | 27057 | | |
27058 | 27058 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9456 | 9456 | | |
9457 | 9457 | | |
9458 | 9458 | | |
9459 | | - | |
| 9459 | + | |
9460 | 9460 | | |
9461 | 9461 | | |
9462 | 9462 | | |
| |||
9498 | 9498 | | |
9499 | 9499 | | |
9500 | 9500 | | |
9501 | | - | |
| 9501 | + | |
9502 | 9502 | | |
9503 | 9503 | | |
9504 | 9504 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10165 | 10165 | | |
10166 | 10166 | | |
10167 | 10167 | | |
10168 | | - | |
| 10168 | + | |
10169 | 10169 | | |
10170 | 10170 | | |
10171 | 10171 | | |
| |||
10220 | 10220 | | |
10221 | 10221 | | |
10222 | 10222 | | |
10223 | | - | |
| 10223 | + | |
10224 | 10224 | | |
10225 | 10225 | | |
10226 | 10226 | | |
| |||
0 commit comments