Commit 8da0da0
authored
Disable timeoutMs argument (#19703)
* Remove distinction between long, short transitions
We're removing the `timeoutMs` option, so there's no longer any
distinction between "short" and "long" transitions. They're all treated
the same.
This commit doesn't remove `timeoutMs` yet, only combines the internal
priority levels.
* Disable `timeoutMs` argument
tl;dr
-----
- We're removing the `timeoutMs` argument from `useTransition`.
- Transitions will either immediately switch to a skeleton/placeholder
view (when loading new content) or wait indefinitely until the data
resolves (when refreshing stale content).
- This commit disables the `timeoutMS` so that the API has the desired
semantics. It doesn't yet update the types or migrate all the test
callers. I'll do those steps in follow-up PRs.
Motivation
----------
Currently, transitions initiated by `startTransition` / `useTransition`
accept a `timeoutMs` option. You can use this to control the maximum
amount of time that a transition is allowed to delay before we give up
and show a placeholder.
What we've discovered is that, in practice, every transition falls into
one of two categories: a **load** or a **refresh**:
- **Loading a new screen**: show the next screen as soon as possible,
even if the data hasn't finished loading. Use a skeleton/placeholder
UI to show progress.
- **Refreshing a screen that's already visible**: keep showing the
current screen indefinitely, for as long as it takes to load the fresh
data, even if the current data is stale. Use a pending state (and
maybe a busy indicator) to show progress.
In other words, transitions should either *delay indefinitely* (for a
refresh) or they should show a placeholder *instantly* (for a load).
There's not much use for transitions that are delayed for a
small-but-noticeable amount of time.
So, the plan is to remove the `timeoutMs` option. Instead, we'll assign
an effective timeout of `0` for loads, and `Infinity` for refreshes.
The mechanism for distinguishing a load from a refresh already exists in
the current model. If a component suspends, and the nearest Suspense
boundary hasn't already mounted, we treat that as a load, because
there's nothing on the screen. However, if the nearest boundary is
mounted, we treat that as a refresh, since it's already showing content.
If you need to fix a transition to be treated as a load instead of a
refresh, or vice versa, the solution will involve rearranging the
location of your Suspense boundaries. It may also involve adding a key.
We're still working on proper documentation for these patterns. In the
meantime, please reach out to us if you run into problems that you're
unsure how to fix.
We will remove `timeoutMs` from `useDeferredValue`, too, and apply the
same load versus refresh semantics to the update that spawns the
deferred value.
Note that there are other types of delays that are not related to
transitions; for example, we will still throttle the appearance of
nested placeholders (we refer to this as the placeholder "train model"),
and we may still apply a Just Noticeable Difference heuristic (JND) in
some cases. These aren't going anywhere. (Well, the JND heuristic might
but for different reasons than those discussed above.)1 parent 60ba723 commit 8da0da0
8 files changed
Lines changed: 254 additions & 372 deletions
File tree
- packages
- react-dom/src/__tests__
- react-reconciler/src
- __tests__
- scripts/error-codes
Lines changed: 13 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
779 | 779 | | |
780 | 780 | | |
781 | 781 | | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
786 | 795 | | |
787 | 796 | | |
788 | 797 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | | - | |
50 | | - | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | | - | |
53 | | - | |
| 52 | + | |
| 53 | + | |
54 | 54 | | |
55 | | - | |
56 | | - | |
| 55 | + | |
| 56 | + | |
57 | 57 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 58 | + | |
| 59 | + | |
63 | 60 | | |
64 | 61 | | |
65 | 62 | | |
| |||
89 | 86 | | |
90 | 87 | | |
91 | 88 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 89 | + | |
| 90 | + | |
97 | 91 | | |
98 | 92 | | |
99 | 93 | | |
| |||
160 | 154 | | |
161 | 155 | | |
162 | 156 | | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
171 | 160 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
180 | 165 | | |
181 | 166 | | |
182 | 167 | | |
| |||
241 | 226 | | |
242 | 227 | | |
243 | 228 | | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
| 229 | + | |
| 230 | + | |
248 | 231 | | |
249 | 232 | | |
250 | 233 | | |
| |||
402 | 385 | | |
403 | 386 | | |
404 | 387 | | |
405 | | - | |
| 388 | + | |
406 | 389 | | |
407 | 390 | | |
408 | 391 | | |
| |||
513 | 496 | | |
514 | 497 | | |
515 | 498 | | |
516 | | - | |
517 | | - | |
518 | | - | |
| 499 | + | |
519 | 500 | | |
520 | 501 | | |
521 | 502 | | |
| |||
525 | 506 | | |
526 | 507 | | |
527 | 508 | | |
528 | | - | |
529 | | - | |
| 509 | + | |
530 | 510 | | |
531 | 511 | | |
532 | 512 | | |
| |||
548 | 528 | | |
549 | 529 | | |
550 | 530 | | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
576 | 539 | | |
577 | | - | |
578 | | - | |
579 | | - | |
580 | | - | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
585 | 543 | | |
586 | | - | |
587 | 544 | | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
| 545 | + | |
593 | 546 | | |
594 | 547 | | |
595 | 548 | | |
| |||
816 | 769 | | |
817 | 770 | | |
818 | 771 | | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
826 | 775 | | |
827 | 776 | | |
828 | 777 | | |
829 | 778 | | |
830 | | - | |
| 779 | + | |
831 | 780 | | |
832 | 781 | | |
833 | 782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
156 | | - | |
157 | | - | |
158 | 156 | | |
159 | 157 | | |
160 | 158 | | |
| |||
457 | 455 | | |
458 | 456 | | |
459 | 457 | | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | 458 | | |
467 | 459 | | |
468 | 460 | | |
469 | 461 | | |
470 | 462 | | |
471 | 463 | | |
472 | | - | |
473 | | - | |
474 | | - | |
475 | | - | |
476 | | - | |
477 | | - | |
| 464 | + | |
478 | 465 | | |
479 | 466 | | |
480 | 467 | | |
| |||
936 | 923 | | |
937 | 924 | | |
938 | 925 | | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
960 | 942 | | |
961 | 943 | | |
962 | | - | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
967 | | - | |
968 | | - | |
969 | | - | |
970 | | - | |
971 | | - | |
972 | | - | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
978 | | - | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
979 | 947 | | |
980 | 948 | | |
981 | 949 | | |
982 | | - | |
983 | | - | |
984 | | - | |
| 950 | + | |
| 951 | + | |
985 | 952 | | |
986 | 953 | | |
987 | 954 | | |
988 | 955 | | |
989 | 956 | | |
990 | 957 | | |
991 | 958 | | |
992 | | - | |
| 959 | + | |
| 960 | + | |
993 | 961 | | |
994 | 962 | | |
995 | 963 | | |
| |||
0 commit comments