Commit a2b2040
committed
fix: don't double-invoke effects for moved children in StrictMode
In StrictMode, `doubleInvokeEffectsInDEVIfNecessary` fires for any
fiber that has the `PlacementDEV` flag set. Previously, `placeChild`
set `PlacementDEV` on both newly inserted fibers AND fibers that were
moved to a different position in an array.
This caused a regression in React 19: when a keyed child is reordered
within an array, its effects are re-run in dev/StrictMode even when
dependencies are empty `[]`. The same component in production, or in
React 18, correctly skips effect re-runs for moves.
The fix is to only set `PlacementDEV` for actual insertions (where
`current === null`). Moved fibers (`current !== null`, `oldIndex <
lastPlacedIndex`) still receive the `Placement` flag so the host node
is correctly repositioned in the DOM, but StrictMode no longer treats
them as new mounts.
Also fix unused `ref3` variable in ReactFabric-test.internal.js
introduced in #35912 (copy-paste: third View used ref2 instead of ref3).
Fixes #325611 parent 7207a65 commit a2b2040
3 files changed
Lines changed: 54 additions & 3 deletions
File tree
- packages
- react-native-renderer/src/__tests__
- react-reconciler/src
- __tests__
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1215 | 1215 | | |
1216 | 1216 | | |
1217 | 1217 | | |
1218 | | - | |
| 1218 | + | |
1219 | 1219 | | |
1220 | 1220 | | |
1221 | 1221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
527 | | - | |
528 | | - | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
529 | 532 | | |
530 | 533 | | |
531 | 534 | | |
| |||
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
964 | 964 | | |
965 | 965 | | |
966 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
967 | 1015 | | |
0 commit comments