Skip to content
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

Enable PPR for dynamic = "force-dynamic" #58779

Merged
merged 11 commits into from
Dec 6, 2023
Merged

Conversation

wyattjoh
Copy link
Member

@wyattjoh wyattjoh commented Nov 22, 2023

This makes some critical modifications to the app render pipeline when PPR has been enabled for pages with segments defining:

export const dynamic = "force-dynamic"

Importantly, it no longer modifies the revalidation time to zero for those pages, and now falls back to the provided default revalidation time. When static render occurs, if the page being rendered has a segment config defining dynamic === "force-dynamic", then it will postpone at the root of the component tree. This ensures that no render code is executed for the page, as the entirety of the tree will have postponed. This fixes the bug where the flight prefetch wasn't generated correctly as well.

@ijjk ijjk added created-by: Next.js team PRs by the Next.js team type: next labels Nov 22, 2023
@wyattjoh
Copy link
Member Author

wyattjoh commented Nov 22, 2023

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@wyattjoh wyattjoh changed the base branch from canary to chore/render-result-cleanup November 22, 2023 17:54
@wyattjoh wyattjoh mentioned this pull request Nov 22, 2023
@ijjk
Copy link
Member

ijjk commented Nov 22, 2023

Tests Passed

@ijjk
Copy link
Member

ijjk commented Nov 22, 2023

Stats from current PR

Default Build (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
buildDuration 10.8s 10.8s N/A
buildDurationCached 5.9s 6.1s ⚠️ +206ms
nodeModulesSize 199 MB 200 MB ⚠️ +72 kB
nextStartRea..uration (ms) 422ms 420ms N/A
Client Bundles (main, webpack)
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
170-HASH.js gzip 30.6 kB 30.3 kB N/A
199.HASH.js gzip 181 B 185 B N/A
3f784ff6-HASH.js gzip 53.3 kB 53.3 kB
framework-HASH.js gzip 45.2 kB 45.2 kB
main-app-HASH.js gzip 240 B 241 B N/A
main-HASH.js gzip 31.7 kB 31.7 kB N/A
webpack-HASH.js gzip 1.7 kB 1.7 kB N/A
Overall change 98.5 kB 98.5 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
_app-HASH.js gzip 195 B 194 B N/A
_error-HASH.js gzip 183 B 182 B N/A
amp-HASH.js gzip 501 B 501 B
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.5 kB 2.5 kB N/A
edge-ssr-HASH.js gzip 255 B 255 B
head-HASH.js gzip 349 B 350 B N/A
hooks-HASH.js gzip 368 B 369 B N/A
image-HASH.js gzip 4.27 kB 4.27 kB N/A
index-HASH.js gzip 255 B 256 B N/A
link-HASH.js gzip 2.6 kB 2.6 kB N/A
routerDirect..HASH.js gzip 311 B 309 B N/A
script-HASH.js gzip 384 B 384 B
withRouter-HASH.js gzip 307 B 306 B N/A
1afbb74e6ecf..834.css gzip 106 B 106 B
Overall change 1.57 kB 1.57 kB
Client Build Manifests
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
_buildManifest.js gzip 483 B 483 B
Overall change 483 B 483 B
Rendered Page Sizes
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
index.html gzip 528 B 528 B
link.html gzip 542 B 542 B
withRouter.html gzip 524 B 524 B
Overall change 1.59 kB 1.59 kB
Edge SSR bundle Size
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
edge-ssr.js gzip 93.5 kB 93.5 kB N/A
page.js gzip 146 kB 146 kB N/A
Overall change 0 B 0 B
Middleware size
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
middleware-b..fest.js gzip 621 B 624 B N/A
middleware-r..fest.js gzip 151 B 151 B
middleware.js gzip 37.5 kB 37.5 kB N/A
edge-runtime..pack.js gzip 1.92 kB 1.92 kB
Overall change 2.07 kB 2.07 kB
Next Runtimes Overall increase ⚠️
vercel/next.js canary vercel/next.js feat/force-dynamic-ppr Change
app-page-exp...dev.js gzip 168 kB 168 kB ⚠️ +214 B
app-page-exp..prod.js gzip 93.8 kB 94 kB ⚠️ +200 B
app-page-tur..prod.js gzip 94.5 kB 94.7 kB ⚠️ +203 B
app-page-tur..prod.js gzip 89.1 kB 89.3 kB ⚠️ +198 B
app-page.run...dev.js gzip 138 kB 138 kB ⚠️ +212 B
app-page.run..prod.js gzip 88.4 kB 88.6 kB ⚠️ +198 B
app-route-ex...dev.js gzip 24.2 kB 24.2 kB N/A
app-route-ex..prod.js gzip 16.8 kB 16.8 kB N/A
app-route-tu..prod.js gzip 16.9 kB 16.8 kB N/A
app-route-tu..prod.js gzip 16.4 kB 16.4 kB N/A
app-route.ru...dev.js gzip 23.6 kB 23.6 kB N/A
app-route.ru..prod.js gzip 16.4 kB 16.4 kB N/A
pages-api-tu..prod.js gzip 9.37 kB 9.37 kB
pages-api.ru...dev.js gzip 9.64 kB 9.64 kB
pages-api.ru..prod.js gzip 9.37 kB 9.37 kB
pages-turbo...prod.js gzip 21.9 kB 21.9 kB N/A
pages.runtim...dev.js gzip 22.6 kB 22.6 kB N/A
pages.runtim..prod.js gzip 21.9 kB 21.9 kB N/A
server.runti..prod.js gzip 49.4 kB 49.4 kB N/A
Overall change 700 kB 701 kB ⚠️ +1.23 kB
Diff details
Diff for page.js

Diff too large to display

Diff for edge-ssr.js

Diff too large to display

Diff for 170-HASH.js

Diff too large to display

Diff for app-page-exp..ntime.dev.js

Diff too large to display

Diff for app-page-exp..time.prod.js

Diff too large to display

Diff for app-page-tur..time.prod.js

Diff too large to display

Diff for app-page-tur..time.prod.js

Diff too large to display

Diff for app-page.runtime.dev.js

Diff too large to display

Diff for app-page.runtime.prod.js

Diff too large to display

Diff for app-route-ex..ntime.dev.js

Diff too large to display

Diff for app-route-ex..time.prod.js

Diff too large to display

Diff for app-route-tu..time.prod.js

Diff too large to display

Diff for app-route-tu..time.prod.js

Diff too large to display

Diff for app-route.runtime.dev.js

Diff too large to display

Diff for app-route.ru..time.prod.js

Diff too large to display

Diff for pages-turbo...time.prod.js

Diff too large to display

Diff for pages.runtime.dev.js

Diff too large to display

Diff for pages.runtime.prod.js

Diff too large to display

Diff for server.runtime.prod.js

Diff too large to display

Commit: 22dd5fe

@wyattjoh wyattjoh force-pushed the chore/render-result-cleanup branch 2 times, most recently from 8bbe107 to 550fc3a Compare November 22, 2023 18:25
@wyattjoh wyattjoh marked this pull request as ready for review November 23, 2023 05:53
@feedthejim
Copy link
Contributor

feedthejim commented Nov 23, 2023

I assume there are not tests because this is tested in the following PR?

if (
staticGenerationStore.forceDynamic &&
staticGenerationStore.isStaticGeneration &&
staticGenerationStore.experimental.ppr
Copy link
Contributor

@acdlite acdlite Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a <MaybePostpone> if you already checked the conditions? maybePostpone checks the same things again. It could really just be <Postpone>.

!staticGenerationStore.isStaticGeneration ||

It looks to me like the only special thing maybePostpone does is set a special field on the static generation store. But this is fishy to me because don’t we need to bail out if React.postpone is called in userspace, too? So this suggests to me we’re either doing something redundant here or we’re missing logic elsewhere to handle the userspace postpone case.

Base automatically changed from chore/render-result-cleanup to canary November 28, 2023 16:10
kodiakhq bot pushed a commit that referenced this pull request Nov 28, 2023
This improves some of the typings around the `RenderResult` returned during renders. Previously it had a single large metadata object that was shared across both the pages and app render pipelines. To add more type safety, this splits the types used by each of the render pipelines into their own types while still allowing the default `RenderResult` to reference metadata from either render pipeline.

This also improved the flight data generation for app renders. Previously, the promise was inlined, and errors were swallowed. With the advent of improvements in #58779 the postpone errors are no longer returned by the flight generation and are instead handled correctly inside the render by React so it can emit properly postponed flight data.

Besides that there was some whitespace changes, so hiding whitespace differences during review should make it much clearer to review!
kodiakhq bot pushed a commit that referenced this pull request Nov 29, 2023
Cherry-picks #58708 without the dependency on #58779

Co-authored-by: Wyatt Johnson <633002+wyattjoh@users.noreply.github.com>
@wyattjoh wyattjoh force-pushed the feat/force-dynamic-ppr branch 4 times, most recently from 209e1c2 to fa728c9 Compare December 5, 2023 08:42
@wyattjoh wyattjoh enabled auto-merge (squash) December 6, 2023 01:06
@wyattjoh wyattjoh merged commit eab1fe8 into canary Dec 6, 2023
64 of 69 checks passed
@wyattjoh wyattjoh deleted the feat/force-dynamic-ppr branch December 6, 2023 01:10
uses: ./.github/workflows/build_reusable.yml
with:
nodeVersion: 18.17.0
afterBuild: node run-tests.js --timings -g ${{ matrix.group }}/12 -c ${TEST_CONCURRENCY} --type integration
afterBuild: node run-tests.js --timings -g ${{ matrix.group }}2 -c ${TEST_CONCURRENCY} --type integration
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wyattjoh This seems like a typo that might introduce a bug? Seems like the 2 in ${{ matrix.group }}2 should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup that was a mistake!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants