-
Notifications
You must be signed in to change notification settings - Fork 7.7k
[wip] Init PPR docs #7869
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
base: main
Are you sure you want to change the base?
[wip] Init PPR docs #7869
Conversation
Size changes📦 Next.js Bundle Analysis for react-devThis analysis was generated by the Next.js Bundle Analysis action. 🤖 One Page Changed SizeThe following page changed size from the code in this PR compared to its base branch:
DetailsOnly the gzipped size is provided here based on an expert tip. First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If Any third party scripts you have added directly to your app using the Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this. |
|
||
```js | ||
import { resume } from 'react-dom/server'; | ||
import {getPostponedState} from 'storage'; |
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.
this looks like a real npm package, is this meant to be something like readFile
?
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.
Loading from the filesystem is probably not going to work right? Typically it would need to be like redis or s3 or something like that.
What about './your-storge-layer'
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.
that seems fine, my main point is just it’s hard to imagine what this is supposed to mean if the format isn’t clear (ie is this just JSON?)
i don’t see why it wouldn’t work via file system though
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.
Yeah we'll clean it up to make it more clear cc @mattcarrollcode
For the file system to work you'd need to serve both the prerender response and the resume request from the same server, which would be uncommon for prod usecases (you're probably scaled to multiple servers, or running vms that can be destroyed between requests, etc). And if you're serving the prerender result from a CDN, it's basically not possible/advisable because you'd need to sync the postpone state to your resume server somehow. So you probably need some kind of permanent storage layer.
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.
Serving the prerender + request from the same server could make sense if you wanted to pre-render some dynamic components at build time, no? For example Remix could expose an API to pre-render some route segments that have dynamic loaders()
(while deferring other segments' loaders()
to execute at request-time).
What about something like this:
import { resume } from 'react-dom/server';
import { storageClient } from './redis'; // or S3, a file, etc.
async function handler(request) {
const postponed = await storageClient.get(request.url);
const stream = await resume(<App />, postponed, {
bootstrapScripts: ['/main.js']
});
return new Response(stream, {
headers: { 'content-type': 'text/html' },
});
}
Also postponed
does have to be JSON, correct? Even though its shape is opaque?
Long way from finished.