-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Partial Pre Rendering Headers #59447
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
20 changes: 20 additions & 0 deletions
20
test/e2e/app-dir/ppr-full/app/dynamic/force-dynamic/nested/[slug]/page.jsx
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,20 @@ | ||
import React, { Suspense } from 'react' | ||
import { Dynamic } from '../../../../../components/dynamic' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
export function generateStaticParams() { | ||
return [] | ||
} | ||
|
||
export default ({ params: { slug } }) => { | ||
return ( | ||
<Suspense | ||
fallback={ | ||
<Dynamic pathname={`/dynamic/force-dynamic/nested/${slug}`} fallback /> | ||
} | ||
> | ||
<Dynamic pathname={`/dynamic/force-dynamic/nested/${slug}`} /> | ||
</Suspense> | ||
) | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import React from 'react' | ||
import { Dynamic } from '../../components/dynamic' | ||
|
||
export default () => { | ||
return <Dynamic pathname="/static" fallback /> | ||
return ( | ||
<dl> | ||
<dt>Pathname</dt> | ||
<dd data-pathname="/static">/static</dd> | ||
</dl> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,37 +1,38 @@ | ||
import React from 'react' | ||
import { headers } from 'next/headers' | ||
import React, { use } from 'react' | ||
import * as next from 'next/headers' | ||
|
||
export const Dynamic = ({ pathname, fallback }) => { | ||
if (fallback) { | ||
return <div>Loading...</div> | ||
return <div>Dynamic Loading...</div> | ||
} | ||
|
||
const headers = next.headers() | ||
const messages = [] | ||
const names = ['x-test-input', 'user-agent'] | ||
const list = headers() | ||
for (const name of ['x-test-input', 'user-agent']) { | ||
messages.push({ name, value: headers.get(name) }) | ||
} | ||
|
||
for (const name of names) { | ||
messages.push({ name, value: list.get(name) }) | ||
const delay = headers.get('x-delay') | ||
if (delay) { | ||
use(new Promise((resolve) => setTimeout(resolve, parseInt(delay, 10)))) | ||
} | ||
|
||
return ( | ||
<div id="needle"> | ||
<dl> | ||
{pathname && ( | ||
<> | ||
<dt>Pathname</dt> | ||
<dd>{pathname}</dd> | ||
</> | ||
)} | ||
{messages.map(({ name, value }) => ( | ||
<React.Fragment key={name}> | ||
<dt> | ||
Header: <code>{name}</code> | ||
</dt> | ||
<dd>{value ?? 'null'}</dd> | ||
</React.Fragment> | ||
))} | ||
</dl> | ||
</div> | ||
<dl> | ||
{pathname && ( | ||
<> | ||
<dt>Pathname</dt> | ||
<dd data-pathname={pathname}>{pathname}</dd> | ||
</> | ||
)} | ||
{messages.map(({ name, value }) => ( | ||
<React.Fragment key={name}> | ||
<dt> | ||
Header: <code>{name}</code> | ||
</dt> | ||
<dd>{value ?? `MISSING:${name.toUpperCase()}`}</dd> | ||
</React.Fragment> | ||
))} | ||
</dl> | ||
) | ||
} |
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,18 @@ | ||
import React from 'react' | ||
import { Links } from './links' | ||
|
||
export const Layout = ({ children }) => { | ||
return ( | ||
<> | ||
<h1>Partial Prerendering</h1> | ||
<p> | ||
Below are links that are associated with different pages that all will | ||
partially prerender | ||
</p> | ||
<aside> | ||
<Links /> | ||
</aside> | ||
<main>{children}</main> | ||
</> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { Layout } from '../components/layout' | ||
|
||
export default () => { | ||
return ( | ||
<Layout> | ||
<dl> | ||
<dt>Pathname</dt> | ||
<dd data-pathname="/pages">/pages</dd> | ||
</dl> | ||
</Layout> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not worth blocking the PR, but: I don't love the use of timers to detect I/O because it's inherently a bit flaky (something unrelated could cause it to be too slow) and it makes the tests run slower.
What I'm planning to do for testing client navigations is spin up an HTTP server and push to an event log whenever the app sends a request, like this:
next.js/test/e2e/app-dir/ppr-navigations/ppr-navigations.test.ts
Lines 19 to 80 in 6b3d145
I like the event log pattern for testing because it also detects things like if the same fetch happens more than once, which is useful for catching caching bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically the delay is to test the "sending the static part of the payload first" behavior of PPR. From my understanding, it's the most black-box way of determining if the static part was cached + sent versus regenerated. I'm not too sure how the logs accomplish the same thing.
I could see using a server like this to instead to send a specific "random" value for it to use (the static value) and then a random value on future renders to help distinguish between what was rendered + returned statically and what was streamed dynamically without reaching into the implementation of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the way I'd write the test is to check that the static content appears in the UI but no requests were made to the HTTP service. The implication then is that the content must have been cached because how else would it have appeared on the page.