Commit be884f0
committed
Warn if optimistic state is updated outside of a transition (#27454)
### Based on #27453
If optimistic state is updated, and there's no startTransition on the
stack, there are two likely scenarios.
One possibility is that the optimistic update is triggered by a regular
event handler (e.g. `onSubmit`) instead of an action. This is a mistake
and we will warn.
The other possibility is the optimistic update is inside an async
action, but after an `await`. In this case, we can make it "just work"
by associating the optimistic update with the pending async action.
Technically it's possible that the optimistic update is unrelated to the
pending action, but we don't have a way of knowing this for sure because
browsers currently do not provide a way to track async scope. (The
AsyncContext proposal, if it lands, will solve this in the future.)
However, this is no different than the problem of unrelated transitions
being grouped together — it's not wrong per se, but it's not ideal.
Once AsyncContext starts landing in browsers, we will provide better
warnings in development for these cases.
DiffTrain build for commit 88d56b8.1 parent 6f227ff commit be884f0
File tree
9 files changed
+20
-20
lines changed- compiled-rn/facebook-fbsource/xplat/js
- RKJSModules/vendor
- react-test-renderer/cjs
- react/cjs
- react-native-github/Libraries/Renderer
- implementations
9 files changed
+20
-20
lines changedLines changed: 4 additions & 4 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 | | |
| |||
8153 | 8153 | | |
8154 | 8154 | | |
8155 | 8155 | | |
| 8156 | + | |
8156 | 8157 | | |
8157 | 8158 | | |
8158 | 8159 | | |
8159 | 8160 | | |
| 8161 | + | |
8160 | 8162 | | |
8161 | 8163 | | |
8162 | | - | |
8163 | | - | |
8164 | 8164 | | |
8165 | 8165 | | |
8166 | 8166 | | |
| |||
23997 | 23997 | | |
23998 | 23998 | | |
23999 | 23999 | | |
24000 | | - | |
| 24000 | + | |
24001 | 24001 | | |
24002 | 24002 | | |
24003 | 24003 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8623 | 8623 | | |
8624 | 8624 | | |
8625 | 8625 | | |
8626 | | - | |
| 8626 | + | |
8627 | 8627 | | |
8628 | 8628 | | |
8629 | 8629 | | |
| |||
8654 | 8654 | | |
8655 | 8655 | | |
8656 | 8656 | | |
8657 | | - | |
| 8657 | + | |
8658 | 8658 | | |
8659 | 8659 | | |
8660 | 8660 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9049 | 9049 | | |
9050 | 9050 | | |
9051 | 9051 | | |
9052 | | - | |
| 9052 | + | |
9053 | 9053 | | |
9054 | 9054 | | |
9055 | 9055 | | |
| |||
9080 | 9080 | | |
9081 | 9081 | | |
9082 | 9082 | | |
9083 | | - | |
| 9083 | + | |
9084 | 9084 | | |
9085 | 9085 | | |
9086 | 9086 | | |
| |||
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 | |
|---|---|---|---|
| |||
616 | 616 | | |
617 | 617 | | |
618 | 618 | | |
619 | | - | |
| 619 | + | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
619 | 619 | | |
620 | 620 | | |
621 | 621 | | |
622 | | - | |
| 622 | + | |
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
Lines changed: 4 additions & 4 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 | | |
| |||
12065 | 12065 | | |
12066 | 12066 | | |
12067 | 12067 | | |
| 12068 | + | |
12068 | 12069 | | |
12069 | 12070 | | |
12070 | 12071 | | |
12071 | 12072 | | |
| 12073 | + | |
12072 | 12074 | | |
12073 | 12075 | | |
12074 | | - | |
12075 | | - | |
12076 | 12076 | | |
12077 | 12077 | | |
12078 | 12078 | | |
| |||
27063 | 27063 | | |
27064 | 27064 | | |
27065 | 27065 | | |
27066 | | - | |
| 27066 | + | |
27067 | 27067 | | |
27068 | 27068 | | |
27069 | 27069 | | |
| |||
Lines changed: 4 additions & 4 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 | | |
| |||
12361 | 12361 | | |
12362 | 12362 | | |
12363 | 12363 | | |
| 12364 | + | |
12364 | 12365 | | |
12365 | 12366 | | |
12366 | 12367 | | |
12367 | 12368 | | |
| 12369 | + | |
12368 | 12370 | | |
12369 | 12371 | | |
12370 | | - | |
12371 | | - | |
12372 | 12372 | | |
12373 | 12373 | | |
12374 | 12374 | | |
| |||
27553 | 27553 | | |
27554 | 27554 | | |
27555 | 27555 | | |
27556 | | - | |
| 27556 | + | |
27557 | 27557 | | |
27558 | 27558 | | |
27559 | 27559 | | |
| |||
0 commit comments