Commit 3d841d7
committed
Unhide Suspense trees without entanglement
When a Suspense boundary is in its fallback state, you cannot switch
back to the main content without also finishing any updates inside the
tree that might have been skipped. That would be a form of tearing.
Before we fixed this in facebook#18411, the way this bug manifested was that a
boundary was suspended by an update that originated from a child
component (as opposed to props from a parent). While the fallback was
showing, it received another update, this time at high priority. React
would render the high priority update without also including the
original update. That would cause the fallback to switch back to the
main content, since the update that caused the tree to suspend was no
longer part of the render. But then, React would immediately try to
render the original update, which would again suspend and show the
fallback, leading to a momentary flicker in the UI.
The approach added in facebook#18411 is, when receiving a high priority update
to a Suspense tree that's in its fallback state is to bail out, keep
showing the fallback and finish the update in the rest of the tree.
After that commits, render again at the original priority. Because low
priority expiration times are inclusive of higher priority expiration
times, this ensures that all the updates are committed together.
The new approach in this commit is to turn `renderExpirationTime` into a
context-like value that lives on the stack. Then, when unhiding the
Suspense boundary, we can push a new `renderExpirationTime` that is
inclusive of both the high pri update and the original update that
suspended. Then the boundary can be unblocked in a single render pass.
An advantage of the old approach is that by deferring the work of
unhiding, there's less work to do in the high priority update.
The key advantage of the new approach is that it solves the consistency
problem without having to entangle the entire root.1 parent 5153267 commit 3d841d7
File tree
7 files changed
+185
-100
lines changed- packages/react-reconciler/src
- __tests__
7 files changed
+185
-100
lines changedLines changed: 64 additions & 65 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
| |||
569 | 570 | | |
570 | 571 | | |
571 | 572 | | |
| 573 | + | |
572 | 574 | | |
573 | 575 | | |
574 | 576 | | |
575 | 577 | | |
576 | 578 | | |
577 | 579 | | |
578 | | - | |
579 | | - | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
580 | 593 | | |
581 | 594 | | |
582 | 595 | | |
| 596 | + | |
583 | 597 | | |
584 | 598 | | |
585 | 599 | | |
| |||
1651 | 1665 | | |
1652 | 1666 | | |
1653 | 1667 | | |
1654 | | - | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
1655 | 1674 | | |
1656 | | - | |
| 1675 | + | |
1657 | 1676 | | |
1658 | | - | |
1659 | 1677 | | |
1660 | | - | |
1661 | 1678 | | |
1662 | 1679 | | |
1663 | 1680 | | |
1664 | | - | |
1665 | | - | |
| 1681 | + | |
| 1682 | + | |
1666 | 1683 | | |
1667 | | - | |
1668 | | - | |
| 1684 | + | |
| 1685 | + | |
1669 | 1686 | | |
1670 | | - | |
| 1687 | + | |
| 1688 | + | |
1671 | 1689 | | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
1678 | | - | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
1679 | 1693 | | |
1680 | | - | |
1681 | 1694 | | |
1682 | 1695 | | |
1683 | 1696 | | |
| |||
1692 | 1705 | | |
1693 | 1706 | | |
1694 | 1707 | | |
1695 | | - | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
1699 | | - | |
1700 | | - | |
1701 | | - | |
1702 | | - | |
1703 | | - | |
1704 | | - | |
1705 | | - | |
1706 | | - | |
1707 | | - | |
| 1708 | + | |
1708 | 1709 | | |
1709 | 1710 | | |
1710 | 1711 | | |
1711 | 1712 | | |
1712 | 1713 | | |
1713 | 1714 | | |
1714 | 1715 | | |
| 1716 | + | |
1715 | 1717 | | |
1716 | 1718 | | |
1717 | 1719 | | |
| |||
1725 | 1727 | | |
1726 | 1728 | | |
1727 | 1729 | | |
1728 | | - | |
1729 | | - | |
1730 | | - | |
1731 | | - | |
1732 | | - | |
1733 | | - | |
1734 | | - | |
1735 | | - | |
1736 | | - | |
1737 | | - | |
1738 | | - | |
1739 | | - | |
1740 | | - | |
1741 | | - | |
1742 | 1730 | | |
1743 | 1731 | | |
1744 | 1732 | | |
| |||
1880 | 1868 | | |
1881 | 1869 | | |
1882 | 1870 | | |
1883 | | - | |
1884 | | - | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
1885 | 1875 | | |
1886 | 1876 | | |
1887 | 1877 | | |
| |||
1935 | 1925 | | |
1936 | 1926 | | |
1937 | 1927 | | |
1938 | | - | |
1939 | | - | |
1940 | | - | |
1941 | | - | |
1942 | | - | |
| 1928 | + | |
1943 | 1929 | | |
1944 | 1930 | | |
1945 | | - | |
| 1931 | + | |
1946 | 1932 | | |
1947 | 1933 | | |
1948 | 1934 | | |
| |||
1959 | 1945 | | |
1960 | 1946 | | |
1961 | 1947 | | |
1962 | | - | |
1963 | | - | |
1964 | | - | |
| 1948 | + | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
1965 | 1957 | | |
1966 | 1958 | | |
1967 | 1959 | | |
1968 | 1960 | | |
1969 | 1961 | | |
1970 | | - | |
1971 | | - | |
1972 | | - | |
1973 | | - | |
| 1962 | + | |
1974 | 1963 | | |
1975 | 1964 | | |
1976 | 1965 | | |
| |||
1997 | 1986 | | |
1998 | 1987 | | |
1999 | 1988 | | |
2000 | | - | |
2001 | | - | |
2002 | | - | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
2003 | 1998 | | |
2004 | 1999 | | |
2005 | 2000 | | |
2006 | 2001 | | |
2007 | 2002 | | |
2008 | 2003 | | |
2009 | 2004 | | |
2010 | | - | |
| 2005 | + | |
2011 | 2006 | | |
2012 | 2007 | | |
2013 | 2008 | | |
| |||
3384 | 3379 | | |
3385 | 3380 | | |
3386 | 3381 | | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
3387 | 3386 | | |
3388 | 3387 | | |
3389 | 3388 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| |||
1299 | 1300 | | |
1300 | 1301 | | |
1301 | 1302 | | |
| 1303 | + | |
1302 | 1304 | | |
1303 | 1305 | | |
1304 | 1306 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
231 | 231 | | |
232 | 232 | | |
233 | 233 | | |
234 | | - | |
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
| |||
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 32 | | |
37 | 33 | | |
38 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
| |||
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
144 | 152 | | |
145 | 153 | | |
146 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
171 | 177 | | |
172 | 178 | | |
173 | 179 | | |
| |||
231 | 237 | | |
232 | 238 | | |
233 | 239 | | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
234 | 246 | | |
235 | 247 | | |
236 | 248 | | |
| |||
1265 | 1277 | | |
1266 | 1278 | | |
1267 | 1279 | | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
1268 | 1293 | | |
1269 | 1294 | | |
1270 | 1295 | | |
| |||
0 commit comments