Commit 1380926
authored
[Segment Bundling] [Scaffolding] Ensure inlining hint correctness (#91320)
Inlining hints (which segments to bundle together) are computed once at
build time by measuring gzip sizes, then persisted to
`prefetch-hints.json`. There are several scenarios where these hints may
not be available at render time. This commit addresses each scenario to
ensure the client always receives correct hints and never enters a bad
state.
### Build-time static pages (stale hints)
The initial RSC payload baked into the HTML is generated before hints
are computed, since hint computation requires at least one completed
render to measure sizes. The server marks these trees with
`InliningHintsStale`. The client immediately expires the route cache
entry so that the next prefetch re-fetches the correct tree from the
`/_tree` response. The segment data doesn't need re-fetching since it
was already cached from the initial HTML payload.
### ISR / revalidation
Hints are always available from the manifest. A missing entry is an
internal error — it means the build pipeline failed to produce hints for
a route that needs them.
### Fully dynamic routes at runtime
No hints exist and none will ever be computed. Every segment gets
`PrefetchDisabled`, which tells the client not to attempt prefetching.
This avoids an infinite re-fetch loop that would occur if the client
kept trying to fetch "correct" hints.
### Unified response format
Also simplifies the segment prefetch response format: every response is
now a `SegmentPrefetchResponse` with a top-level `buildId` and a `data`
array, treating a single-segment response as a bundle that happens to
have length one. This unifies the format so that bundled multi-segment
responses (added in a follow-up) require no additional client parsing
logic.1 parent cbb5879 commit 1380926
19 files changed
Lines changed: 425 additions & 78 deletions
File tree
- packages/next
- src
- client/components
- router-reducer
- segment-cache
- server/app-render
- test
- e2e/app-dir/segment-cache/prefetch-inlining
- app
- test-instant-false-root
- test-stale-hints
- nested
- deep
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1140 | 1140 | | |
1141 | 1141 | | |
1142 | 1142 | | |
1143 | | - | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
1144 | 1148 | | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
Lines changed: 57 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
452 | 453 | | |
453 | 454 | | |
454 | 455 | | |
455 | | - | |
| 456 | + | |
456 | 457 | | |
457 | 458 | | |
458 | 459 | | |
| |||
1070 | 1071 | | |
1071 | 1072 | | |
1072 | 1073 | | |
1073 | | - | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
1074 | 1085 | | |
1075 | 1086 | | |
1076 | 1087 | | |
| |||
1924 | 1935 | | |
1925 | 1936 | | |
1926 | 1937 | | |
1927 | | - | |
1928 | | - | |
1929 | | - | |
1930 | | - | |
1931 | | - | |
| 1938 | + | |
| 1939 | + | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
| 1943 | + | |
1932 | 1944 | | |
1933 | 1945 | | |
1934 | | - | |
| 1946 | + | |
1935 | 1947 | | |
1936 | 1948 | | |
1937 | 1949 | | |
1938 | 1950 | | |
1939 | 1951 | | |
1940 | 1952 | | |
1941 | | - | |
1942 | | - | |
1943 | | - | |
1944 | | - | |
1945 | | - | |
1946 | | - | |
1947 | | - | |
1948 | | - | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
| 1961 | + | |
| 1962 | + | |
| 1963 | + | |
| 1964 | + | |
| 1965 | + | |
| 1966 | + | |
| 1967 | + | |
| 1968 | + | |
| 1969 | + | |
| 1970 | + | |
| 1971 | + | |
1949 | 1972 | | |
1950 | | - | |
1951 | | - | |
1952 | | - | |
1953 | | - | |
1954 | | - | |
1955 | | - | |
1956 | | - | |
1957 | | - | |
1958 | | - | |
1959 | | - | |
1960 | | - | |
1961 | | - | |
1962 | | - | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
1963 | 1989 | | |
1964 | 1990 | | |
1965 | 1991 | | |
| |||
2037 | 2063 | | |
2038 | 2064 | | |
2039 | 2065 | | |
2040 | | - | |
| 2066 | + | |
2041 | 2067 | | |
2042 | 2068 | | |
2043 | 2069 | | |
| |||
Lines changed: 42 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
140 | 166 | | |
141 | 167 | | |
142 | 168 | | |
| |||
442 | 468 | | |
443 | 469 | | |
444 | 470 | | |
445 | | - | |
| 471 | + | |
| 472 | + | |
446 | 473 | | |
447 | 474 | | |
448 | | - | |
| 475 | + | |
449 | 476 | | |
450 | | - | |
| 477 | + | |
451 | 478 | | |
452 | 479 | | |
453 | 480 | | |
| |||
486 | 513 | | |
487 | 514 | | |
488 | 515 | | |
| 516 | + | |
489 | 517 | | |
490 | 518 | | |
491 | 519 | | |
492 | 520 | | |
493 | 521 | | |
494 | 522 | | |
| 523 | + | |
495 | 524 | | |
496 | 525 | | |
497 | 526 | | |
| |||
593 | 622 | | |
594 | 623 | | |
595 | 624 | | |
| 625 | + | |
596 | 626 | | |
597 | 627 | | |
598 | 628 | | |
| |||
610 | 640 | | |
611 | 641 | | |
612 | 642 | | |
613 | | - | |
| 643 | + | |
614 | 644 | | |
615 | 645 | | |
616 | 646 | | |
| |||
636 | 666 | | |
637 | 667 | | |
638 | 668 | | |
| 669 | + | |
639 | 670 | | |
640 | 671 | | |
641 | 672 | | |
| |||
658 | 689 | | |
659 | 690 | | |
660 | 691 | | |
661 | | - | |
| 692 | + | |
662 | 693 | | |
663 | 694 | | |
664 | 695 | | |
| |||
672 | 703 | | |
673 | 704 | | |
674 | 705 | | |
675 | | - | |
| 706 | + | |
676 | 707 | | |
677 | 708 | | |
678 | 709 | | |
| |||
681 | 712 | | |
682 | 713 | | |
683 | 714 | | |
684 | | - | |
| 715 | + | |
| 716 | + | |
685 | 717 | | |
686 | 718 | | |
687 | 719 | | |
688 | 720 | | |
689 | 721 | | |
| 722 | + | |
690 | 723 | | |
691 | 724 | | |
692 | 725 | | |
693 | 726 | | |
694 | 727 | | |
695 | 728 | | |
696 | 729 | | |
| 730 | + | |
697 | 731 | | |
698 | 732 | | |
699 | 733 | | |
| |||
721 | 755 | | |
722 | 756 | | |
723 | 757 | | |
724 | | - | |
| 758 | + | |
725 | 759 | | |
726 | 760 | | |
727 | 761 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
1733 | 1734 | | |
1734 | 1735 | | |
1735 | 1736 | | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
1736 | 1740 | | |
1737 | 1741 | | |
1738 | 1742 | | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
1739 | 1746 | | |
1740 | 1747 | | |
1741 | 1748 | | |
| |||
1924 | 1931 | | |
1925 | 1932 | | |
1926 | 1933 | | |
| 1934 | + | |
| 1935 | + | |
| 1936 | + | |
1927 | 1937 | | |
1928 | 1938 | | |
1929 | 1939 | | |
| 1940 | + | |
| 1941 | + | |
| 1942 | + | |
1930 | 1943 | | |
1931 | 1944 | | |
1932 | 1945 | | |
| |||
7244 | 7257 | | |
7245 | 7258 | | |
7246 | 7259 | | |
7247 | | - | |
| 7260 | + | |
| 7261 | + | |
| 7262 | + | |
| 7263 | + | |
| 7264 | + | |
| 7265 | + | |
| 7266 | + | |
| 7267 | + | |
| 7268 | + | |
| 7269 | + | |
| 7270 | + | |
| 7271 | + | |
| 7272 | + | |
| 7273 | + | |
| 7274 | + | |
| 7275 | + | |
| 7276 | + | |
| 7277 | + | |
| 7278 | + | |
| 7279 | + | |
| 7280 | + | |
7248 | 7281 | | |
7249 | 7282 | | |
7250 | 7283 | | |
| |||
0 commit comments