-
Notifications
You must be signed in to change notification settings - Fork 8
Pass through prerender classification metadata to prerender-config.json #80
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
Open
agadzik
wants to merge
1
commit into
nextjs:main
Choose a base branch
from
agadzik:gadzik/add-ppr-metadata-prerender
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 hidden or 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,5 @@ | ||
| --- | ||
| "@next-community/adapter-vercel": patch | ||
| --- | ||
|
|
||
| Pass through prerender classification metadata (`hasPostponed`, `hasFallback`, `htmlSize`, `isDynamicRoute`) from `AdapterOutput['PRERENDER']` to `prerender-config.json`, matching the `@vercel/next` builder so deployment summaries can classify PPR and Cache Components routes. The fields are tri-state: `false`/`0` are written as-is and only `undefined` is omitted. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| import fs from 'node:fs/promises'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import type { AdapterOutput } from 'next'; | ||
| import { AdapterOutputType } from 'next/dist/shared/lib/constants'; | ||
| import { afterEach, beforeEach, describe, expect, it } from 'vitest'; | ||
| import type { FuncOutputs } from './outputs'; | ||
| import { handlePrerenderOutputs } from './outputs'; | ||
|
|
||
| describe('handlePrerenderOutputs', () => { | ||
| let vercelOutputDir: string; | ||
|
|
||
| beforeEach(async () => { | ||
| vercelOutputDir = await fs.mkdtemp( | ||
| path.join(os.tmpdir(), 'adapter-vercel-test-') | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await fs.rm(vercelOutputDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| function createPrerenderOutput( | ||
| extraFields: Record<string, unknown> = {} | ||
| ): AdapterOutput['PRERENDER'] { | ||
| return { | ||
| id: 'prerender-1', | ||
| pathname: '/blog/hello', | ||
| type: AdapterOutputType.PRERENDER, | ||
| parentOutputId: 'parent-1', | ||
| groupId: 1, | ||
| config: { | ||
| allowQuery: ['slug'], | ||
| allowHeader: ['x-prerender-revalidate'], | ||
| }, | ||
| ...extraFields, | ||
| } as AdapterOutput['PRERENDER']; | ||
| } | ||
|
|
||
| async function runAndReadConfig(output: AdapterOutput['PRERENDER']) { | ||
| const nodeOutputsParentMap = new Map<string, FuncOutputs[0]>([ | ||
| ['parent-1', { pathname: '/blog/hello' } as FuncOutputs[0]], | ||
| ]); | ||
|
|
||
| await handlePrerenderOutputs([output], { | ||
| config: {}, | ||
| vercelOutputDir, | ||
| nodeOutputsParentMap, | ||
| rscContentType: 'text/x-component', | ||
| varyHeader: 'RSC', | ||
| }); | ||
|
|
||
| return fs.readFile( | ||
| path.join( | ||
| vercelOutputDir, | ||
| 'functions', | ||
| 'blog/hello.prerender-config.json' | ||
| ), | ||
| 'utf8' | ||
| ); | ||
| } | ||
|
|
||
| it('passes prerender classification metadata through without collapsing false/0', async () => { | ||
| const rawConfig = await runAndReadConfig( | ||
| createPrerenderOutput({ | ||
| hasPostponed: true, | ||
| hasFallback: false, | ||
| htmlSize: 0, | ||
| isDynamicRoute: true, | ||
| }) | ||
| ); | ||
|
|
||
| const parsedConfig = JSON.parse(rawConfig); | ||
| expect(parsedConfig.hasPostponed).toBe(true); | ||
| expect(parsedConfig.hasFallback).toBe(false); | ||
| expect(parsedConfig.htmlSize).toBe(0); | ||
| expect(parsedConfig.isDynamicRoute).toBe(true); | ||
| }); | ||
|
|
||
| it('omits classification keys when the fields are not provided', async () => { | ||
| const rawConfig = await runAndReadConfig(createPrerenderOutput()); | ||
|
|
||
| expect(rawConfig).not.toContain('hasPostponed'); | ||
| expect(rawConfig).not.toContain('hasFallback'); | ||
| expect(rawConfig).not.toContain('htmlSize'); | ||
| expect(rawConfig).not.toContain('isDynamicRoute'); | ||
| }); | ||
| }); |
This file contains hidden or 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
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.
We should be able to remove this once the Nextjs side is merged. then bumping the next canary version dependency here will give you the true types.
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, wont merge this until the next changes are merged and I make this change!