Commit f2e24bd
committed
Retain in-progress caches on the root, per lane
All the data that loaded as a result of a single transition/update
should share the same cache. This includes nested content that gets
progressively "filled in" after the initial shell is displayed.
If the shell itself were wrapped in a Cache boundary, such that the
cache can commit with suspending, then this is easy: once the boundary
mounts, the cache is attached the React tree.
The tricky part is when the shell does not include a cache boundary. In
the naive approach, since the cache is not part of the initial tree, it
does not get retained; during the retry, a fresh cache is created,
leading to duplicate requests and possibly an infinite loop as requests
are endlessly created then discarded.
This is the essential problem we faced several years ago when building
Simple Cache Provider (later the react-cache package).
Our solution is to retain in-flight caches on the root, associated by
lane. The cache cleared from the root once all of the lanes that depend
on it finish rendering.
Because progressively rendering nested boundaries ("retry" updates) uses
a different lane from the update that spawned it, we must take extra
care to transfer the cache to the new lane when scheduling the retry.1 parent 299405f commit f2e24bd
File tree
10 files changed
+560
-61
lines changed- packages/react-reconciler/src
- __tests__
10 files changed
+560
-61
lines changedLines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
1488 | 1490 | | |
1489 | 1491 | | |
1490 | 1492 | | |
1491 | | - | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
1492 | 1498 | | |
1493 | 1499 | | |
1494 | 1500 | | |
| |||
1524 | 1530 | | |
1525 | 1531 | | |
1526 | 1532 | | |
1527 | | - | |
| 1533 | + | |
1528 | 1534 | | |
1529 | 1535 | | |
1530 | 1536 | | |
1531 | | - | |
| 1537 | + | |
1532 | 1538 | | |
1533 | 1539 | | |
1534 | 1540 | | |
| |||
1639 | 1645 | | |
1640 | 1646 | | |
1641 | 1647 | | |
1642 | | - | |
| 1648 | + | |
1643 | 1649 | | |
1644 | 1650 | | |
1645 | 1651 | | |
1646 | | - | |
| 1652 | + | |
1647 | 1653 | | |
1648 | 1654 | | |
1649 | 1655 | | |
| |||
1672 | 1678 | | |
1673 | 1679 | | |
1674 | 1680 | | |
| 1681 | + | |
| 1682 | + | |
1675 | 1683 | | |
1676 | 1684 | | |
1677 | 1685 | | |
| |||
1747 | 1755 | | |
1748 | 1756 | | |
1749 | 1757 | | |
1750 | | - | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
1751 | 1762 | | |
1752 | 1763 | | |
1753 | 1764 | | |
| |||
1760 | 1771 | | |
1761 | 1772 | | |
1762 | 1773 | | |
1763 | | - | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
1764 | 1780 | | |
1765 | 1781 | | |
1766 | 1782 | | |
| |||
Lines changed: 23 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
1489 | 1491 | | |
1490 | 1492 | | |
1491 | 1493 | | |
1492 | | - | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1493 | 1499 | | |
1494 | 1500 | | |
1495 | 1501 | | |
| |||
1525 | 1531 | | |
1526 | 1532 | | |
1527 | 1533 | | |
1528 | | - | |
| 1534 | + | |
1529 | 1535 | | |
1530 | 1536 | | |
1531 | 1537 | | |
1532 | | - | |
| 1538 | + | |
1533 | 1539 | | |
1534 | 1540 | | |
1535 | 1541 | | |
| |||
1640 | 1646 | | |
1641 | 1647 | | |
1642 | 1648 | | |
1643 | | - | |
| 1649 | + | |
1644 | 1650 | | |
1645 | 1651 | | |
1646 | 1652 | | |
1647 | | - | |
| 1653 | + | |
1648 | 1654 | | |
1649 | 1655 | | |
1650 | 1656 | | |
| |||
1673 | 1679 | | |
1674 | 1680 | | |
1675 | 1681 | | |
| 1682 | + | |
| 1683 | + | |
1676 | 1684 | | |
1677 | 1685 | | |
1678 | 1686 | | |
| |||
1748 | 1756 | | |
1749 | 1757 | | |
1750 | 1758 | | |
1751 | | - | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
1752 | 1763 | | |
1753 | 1764 | | |
1754 | 1765 | | |
| |||
1761 | 1772 | | |
1762 | 1773 | | |
1763 | 1774 | | |
1764 | | - | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
1765 | 1781 | | |
1766 | 1782 | | |
1767 | 1783 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
742 | 742 | | |
743 | 743 | | |
744 | 744 | | |
| 745 | + | |
745 | 746 | | |
746 | 747 | | |
747 | 748 | | |
| |||
753 | 754 | | |
754 | 755 | | |
755 | 756 | | |
756 | | - | |
757 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
758 | 780 | | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
| 781 | + | |
765 | 782 | | |
766 | 783 | | |
767 | 784 | | |
| |||
785 | 802 | | |
786 | 803 | | |
787 | 804 | | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
794 | 861 | | |
795 | 862 | | |
796 | 863 | | |
| |||
801 | 868 | | |
802 | 869 | | |
803 | 870 | | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
804 | 881 | | |
805 | 882 | | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
806 | 924 | | |
807 | 925 | | |
808 | 926 | | |
| |||
0 commit comments