-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Segment Cache] Skip prefetched segments on server
Currently if you navigate to a partially static route, the server will always start rendering at the first segment that's not present on the previous page. However, it should really start rendering at the first *dynamic* segment — if the client has already prefetched a segment, and it's fully static, there's no reason to render it again during the dynamic server render. We can do this by sending a more specific Next-Router-State-Tree request header. Rather than send a tree that represents the previous route, we sent the tree of the target route, but with a `refetch` marker added to the first dynamic segment. (Without the refetch marker, the server would send back an empty response.) This is determined by diffing againt both the previous route *and* the prefetch cache. For now, this only works up to the first dynamic segment inside the new subtree; once the server starts rendering along a path, it renders everything else along that path. We could improve this in the future to also omit static segments that appear inside a dynamic layout, though this would likely require a change to the Next-Router-State- Tree protocol.
- Loading branch information
Showing
7 changed files
with
177 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/e2e/app-dir/segment-cache/basic/app/partially-static/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Link from 'next/link' | ||
|
||
export default function FullyStaticStart() { | ||
return ( | ||
<> | ||
<p> | ||
Demonstrates that when navigating to a partially static route, the | ||
server does not render static layouts that were already prefetched. | ||
</p> | ||
<ul> | ||
<li> | ||
<Link href="/partially-static/target-page">Target</Link> | ||
</li> | ||
</ul> | ||
</> | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/segment-cache/basic/app/partially-static/target-page/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default function StaticLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<> | ||
<div id="static-layout">Static layout</div> | ||
<div>{children}</div> | ||
</> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
test/e2e/app-dir/segment-cache/basic/app/partially-static/target-page/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Suspense } from 'react' | ||
import { connection } from 'next/server' | ||
|
||
async function Content() { | ||
await connection() | ||
return 'Dynamic page' | ||
} | ||
|
||
export default function DynamicPage() { | ||
return ( | ||
<div id="dynamic-page"> | ||
<Suspense fallback="Loading..."> | ||
<Content /> | ||
</Suspense> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters