Commit 1589271
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: #30889
DiffTrain build for commit 727b361.1 parent 6f1fca9 commit 1589271
File tree
14 files changed
+267
-213
lines changed- compiled-rn
- facebook-fbsource/xplat/js
- RKJSModules/vendor/react
- react-test-renderer/cjs
- react/cjs
- react-native-github/Libraries/Renderer
- implementations
14 files changed
+267
-213
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 25 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
3776 | 3776 | | |
3777 | 3777 | | |
3778 | 3778 | | |
3779 | | - | |
| 3779 | + | |
| 3780 | + | |
| 3781 | + | |
| 3782 | + | |
| 3783 | + | |
| 3784 | + | |
| 3785 | + | |
3780 | 3786 | | |
3781 | 3787 | | |
3782 | | - | |
| 3788 | + | |
3783 | 3789 | | |
3784 | 3790 | | |
3785 | 3791 | | |
| |||
4524 | 4530 | | |
4525 | 4531 | | |
4526 | 4532 | | |
4527 | | - | |
4528 | | - | |
4529 | | - | |
4530 | | - | |
4531 | | - | |
4532 | | - | |
4533 | | - | |
4534 | | - | |
4535 | | - | |
4536 | | - | |
4537 | | - | |
| 4533 | + | |
| 4534 | + | |
| 4535 | + | |
| 4536 | + | |
| 4537 | + | |
| 4538 | + | |
| 4539 | + | |
| 4540 | + | |
| 4541 | + | |
| 4542 | + | |
4538 | 4543 | | |
4539 | 4544 | | |
4540 | 4545 | | |
| |||
6101 | 6106 | | |
6102 | 6107 | | |
6103 | 6108 | | |
| 6109 | + | |
6104 | 6110 | | |
6105 | 6111 | | |
6106 | 6112 | | |
| |||
15051 | 15057 | | |
15052 | 15058 | | |
15053 | 15059 | | |
15054 | | - | |
| 15060 | + | |
15055 | 15061 | | |
15056 | 15062 | | |
15057 | 15063 | | |
15058 | | - | |
| 15064 | + | |
15059 | 15065 | | |
15060 | 15066 | | |
15061 | 15067 | | |
| |||
15077 | 15083 | | |
15078 | 15084 | | |
15079 | 15085 | | |
15080 | | - | |
| 15086 | + | |
15081 | 15087 | | |
15082 | 15088 | | |
15083 | 15089 | | |
| |||
15200 | 15206 | | |
15201 | 15207 | | |
15202 | 15208 | | |
15203 | | - | |
| 15209 | + | |
15204 | 15210 | | |
Lines changed: 30 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
2406 | 2406 | | |
2407 | 2407 | | |
2408 | 2408 | | |
2409 | | - | |
| 2409 | + | |
| 2410 | + | |
| 2411 | + | |
| 2412 | + | |
| 2413 | + | |
| 2414 | + | |
| 2415 | + | |
2410 | 2416 | | |
2411 | | - | |
| 2417 | + | |
2412 | 2418 | | |
2413 | 2419 | | |
2414 | 2420 | | |
| |||
2997 | 3003 | | |
2998 | 3004 | | |
2999 | 3005 | | |
3000 | | - | |
3001 | | - | |
3002 | | - | |
3003 | | - | |
3004 | | - | |
3005 | | - | |
3006 | | - | |
3007 | | - | |
3008 | | - | |
3009 | | - | |
3010 | | - | |
| 3006 | + | |
| 3007 | + | |
| 3008 | + | |
| 3009 | + | |
| 3010 | + | |
| 3011 | + | |
| 3012 | + | |
| 3013 | + | |
| 3014 | + | |
| 3015 | + | |
3011 | 3016 | | |
3012 | 3017 | | |
3013 | 3018 | | |
| |||
4228 | 4233 | | |
4229 | 4234 | | |
4230 | 4235 | | |
| 4236 | + | |
4231 | 4237 | | |
4232 | 4238 | | |
4233 | 4239 | | |
| |||
9437 | 9443 | | |
9438 | 9444 | | |
9439 | 9445 | | |
9440 | | - | |
| 9446 | + | |
9441 | 9447 | | |
9442 | | - | |
| 9448 | + | |
9443 | 9449 | | |
9444 | 9450 | | |
9445 | 9451 | | |
9446 | 9452 | | |
9447 | 9453 | | |
9448 | 9454 | | |
9449 | | - | |
| 9455 | + | |
9450 | 9456 | | |
9451 | 9457 | | |
9452 | | - | |
| 9458 | + | |
9453 | 9459 | | |
9454 | | - | |
9455 | | - | |
| 9460 | + | |
| 9461 | + | |
9456 | 9462 | | |
9457 | 9463 | | |
9458 | | - | |
9459 | | - | |
| 9464 | + | |
| 9465 | + | |
9460 | 9466 | | |
9461 | | - | |
| 9467 | + | |
9462 | 9468 | | |
9463 | 9469 | | |
9464 | 9470 | | |
| |||
9582 | 9588 | | |
9583 | 9589 | | |
9584 | 9590 | | |
9585 | | - | |
| 9591 | + | |
Lines changed: 30 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
2483 | 2483 | | |
2484 | 2484 | | |
2485 | 2485 | | |
2486 | | - | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
2487 | 2493 | | |
2488 | | - | |
| 2494 | + | |
2489 | 2495 | | |
2490 | 2496 | | |
2491 | 2497 | | |
| |||
3074 | 3080 | | |
3075 | 3081 | | |
3076 | 3082 | | |
3077 | | - | |
3078 | | - | |
3079 | | - | |
3080 | | - | |
3081 | | - | |
3082 | | - | |
3083 | | - | |
3084 | | - | |
3085 | | - | |
3086 | | - | |
3087 | | - | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
3088 | 3093 | | |
3089 | 3094 | | |
3090 | 3095 | | |
| |||
4380 | 4385 | | |
4381 | 4386 | | |
4382 | 4387 | | |
| 4388 | + | |
4383 | 4389 | | |
4384 | 4390 | | |
4385 | 4391 | | |
| |||
10025 | 10031 | | |
10026 | 10032 | | |
10027 | 10033 | | |
10028 | | - | |
| 10034 | + | |
10029 | 10035 | | |
10030 | | - | |
| 10036 | + | |
10031 | 10037 | | |
10032 | 10038 | | |
10033 | 10039 | | |
10034 | 10040 | | |
10035 | 10041 | | |
10036 | 10042 | | |
10037 | | - | |
| 10043 | + | |
10038 | 10044 | | |
10039 | 10045 | | |
10040 | 10046 | | |
| |||
10052 | 10058 | | |
10053 | 10059 | | |
10054 | 10060 | | |
10055 | | - | |
| 10061 | + | |
10056 | 10062 | | |
10057 | | - | |
10058 | | - | |
| 10063 | + | |
| 10064 | + | |
10059 | 10065 | | |
10060 | 10066 | | |
10061 | | - | |
10062 | | - | |
| 10067 | + | |
| 10068 | + | |
10063 | 10069 | | |
10064 | | - | |
| 10070 | + | |
10065 | 10071 | | |
10066 | 10072 | | |
10067 | 10073 | | |
| |||
10185 | 10191 | | |
10186 | 10192 | | |
10187 | 10193 | | |
10188 | | - | |
| 10194 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
1705 | 1705 | | |
1706 | 1706 | | |
1707 | 1707 | | |
1708 | | - | |
| 1708 | + | |
1709 | 1709 | | |
1710 | 1710 | | |
1711 | 1711 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
583 | | - | |
| 583 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
| 587 | + | |
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
0 commit comments