Commit 727b361
committed
Fix useMemoCache with setState in render
Fixes the bug that @alexmckenley and @mofeiZ found where setState-in-render can reset useMemoCache and cause an infinite loop. The bug was that renderWithHooksAgain() was not resetting hook state when rerendering (so useMemo values were preserved) but was resetting the updateQueue. This meant that the entire memo cache was cleared on a setState-in-render.
The fix here is to call a new helper function to clear the update queue. It nulls out other properties, but for memoCache it just sets the index back to zero.
ghstack-source-id: fc0947c
Pull Request resolved: #308891 parent bd788b4 commit 727b361
File tree
2 files changed
+42
-24
lines changed- packages/react-reconciler/src
- __tests__
2 files changed
+42
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
770 | 770 | | |
771 | 771 | | |
772 | 772 | | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
773 | 779 | | |
774 | 780 | | |
775 | 781 | | |
| |||
828 | 834 | | |
829 | 835 | | |
830 | 836 | | |
831 | | - | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
832 | 840 | | |
833 | 841 | | |
834 | 842 | | |
| |||
1101 | 1109 | | |
1102 | 1110 | | |
1103 | 1111 | | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1104 | 1128 | | |
1105 | 1129 | | |
1106 | 1130 | | |
| |||
2496 | 2520 | | |
2497 | 2521 | | |
2498 | 2522 | | |
| 2523 | + | |
| 2524 | + | |
| 2525 | + | |
2499 | 2526 | | |
2500 | 2527 | | |
2501 | | - | |
2502 | | - | |
2503 | | - | |
2504 | | - | |
2505 | | - | |
2506 | | - | |
2507 | | - | |
2508 | | - | |
2509 | | - | |
| 2528 | + | |
| 2529 | + | |
| 2530 | + | |
| 2531 | + | |
2510 | 2532 | | |
2511 | 2533 | | |
2512 | 2534 | | |
| |||
Lines changed: 10 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
| |||
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
35 | | - | |
36 | 34 | | |
37 | 35 | | |
38 | 36 | | |
| |||
667 | 665 | | |
668 | 666 | | |
669 | 667 | | |
670 | | - | |
| 668 | + | |
671 | 669 | | |
672 | 670 | | |
673 | 671 | | |
| |||
683 | 681 | | |
684 | 682 | | |
685 | 683 | | |
686 | | - | |
| 684 | + | |
687 | 685 | | |
688 | 686 | | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
695 | 692 | | |
696 | 693 | | |
697 | | - | |
698 | | - | |
| 694 | + | |
699 | 695 | | |
700 | 696 | | |
701 | | - | |
| 697 | + | |
702 | 698 | | |
703 | | - | |
| 699 | + | |
704 | 700 | | |
705 | 701 | | |
706 | 702 | | |
| |||
0 commit comments