Commit 2a83d9a
committed
Async action support for React.startTransition
This adds support for async actions to the "isomorphic" version of
startTransition (i.e. the one exported by the "react" package).
Previously, async actions were only supported by the startTransition
that is returned from the useTransition hook.
The interesting part about the isomorphic startTransition is that it's
not associated with any particular root. It must work with updates to
arbitrary roots, or even arbitrary React renderers in the same app. (For
example, both React DOM and React Three Fiber.)
The idea is that React.startTransition should behave as if every root
had an implicit useTransition hook, and you composed together all the
startTransitions provided by those hooks. Multiple updates to the same
root will be batched together. However, updates to one root will not be
batched with updates to other roots.
Features like useOptimistic work the same as with the hook version.
There is one difference from from the hook version of startTransition:
an error triggered inside an async action cannot be captured by an error
boundary, because it's not associated with any particular part of the
tree. You should handle errors the same way you would in a regular
event, e.g. with a global error event handler, or with a
local `try/catch`.1 parent c7e735f commit 2a83d9a
File tree
8 files changed
+195
-34
lines changed- packages
- react-reconciler/src
- __tests__
- react/src
8 files changed
+195
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | | - | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
149 | 148 | | |
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
154 | 153 | | |
155 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
156 | 159 | | |
157 | 160 | | |
158 | 161 | | |
| |||
1319 | 1322 | | |
1320 | 1323 | | |
1321 | 1324 | | |
1322 | | - | |
1323 | | - | |
1324 | | - | |
1325 | | - | |
1326 | | - | |
1327 | | - | |
1328 | | - | |
1329 | 1325 | | |
1330 | 1326 | | |
1331 | 1327 | | |
| |||
1346 | 1342 | | |
1347 | 1343 | | |
1348 | 1344 | | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
1349 | 1352 | | |
1350 | 1353 | | |
1351 | 1354 | | |
| |||
1356 | 1359 | | |
1357 | 1360 | | |
1358 | 1361 | | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
1359 | 1369 | | |
1360 | 1370 | | |
1361 | 1371 | | |
| |||
1964 | 1974 | | |
1965 | 1975 | | |
1966 | 1976 | | |
1967 | | - | |
1968 | | - | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
1969 | 1981 | | |
1970 | 1982 | | |
1971 | 1983 | | |
1972 | 1984 | | |
1973 | 1985 | | |
| 1986 | + | |
| 1987 | + | |
1974 | 1988 | | |
1975 | 1989 | | |
1976 | 1990 | | |
| |||
1989 | 2003 | | |
1990 | 2004 | | |
1991 | 2005 | | |
1992 | | - | |
1993 | 2006 | | |
1994 | 2007 | | |
1995 | 2008 | | |
| |||
2808 | 2821 | | |
2809 | 2822 | | |
2810 | 2823 | | |
2811 | | - | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
2812 | 2827 | | |
2813 | 2828 | | |
2814 | 2829 | | |
| |||
2839 | 2854 | | |
2840 | 2855 | | |
2841 | 2856 | | |
| 2857 | + | |
2842 | 2858 | | |
2843 | 2859 | | |
2844 | 2860 | | |
| |||
2854 | 2870 | | |
2855 | 2871 | | |
2856 | 2872 | | |
2857 | | - | |
2858 | 2873 | | |
2859 | 2874 | | |
2860 | 2875 | | |
| |||
3281 | 3296 | | |
3282 | 3297 | | |
3283 | 3298 | | |
| 3299 | + | |
| 3300 | + | |
3284 | 3301 | | |
3285 | | - | |
| 3302 | + | |
3286 | 3303 | | |
3287 | 3304 | | |
3288 | 3305 | | |
| |||
3323 | 3340 | | |
3324 | 3341 | | |
3325 | 3342 | | |
3326 | | - | |
| 3343 | + | |
3327 | 3344 | | |
3328 | 3345 | | |
3329 | 3346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
492 | 493 | | |
493 | 494 | | |
494 | 495 | | |
495 | | - | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
496 | 502 | | |
497 | 503 | | |
498 | 504 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
| 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 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
16 | 24 | | |
17 | 25 | | |
18 | 26 | | |
| |||
26 | 34 | | |
27 | 35 | | |
28 | 36 | | |
| 37 | + | |
29 | 38 | | |
30 | 39 | | |
31 | 40 | | |
32 | 41 | | |
33 | 42 | | |
34 | | - | |
35 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
36 | 75 | | |
37 | 76 | | |
38 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
164 | 165 | | |
165 | 166 | | |
166 | 167 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | | - | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| |||
633 | 634 | | |
634 | 635 | | |
635 | 636 | | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
642 | 643 | | |
643 | 644 | | |
644 | | - | |
| 645 | + | |
645 | 646 | | |
646 | 647 | | |
647 | 648 | | |
| |||
651 | 652 | | |
652 | 653 | | |
653 | 654 | | |
654 | | - | |
| 655 | + | |
655 | 656 | | |
656 | 657 | | |
657 | 658 | | |
| |||
712 | 713 | | |
713 | 714 | | |
714 | 715 | | |
715 | | - | |
| 716 | + | |
716 | 717 | | |
717 | 718 | | |
718 | 719 | | |
| |||
0 commit comments