Skip to content

Commit 8217f50

Browse files
authoredMar 11, 2024
fix: avoid PPR build error (#286)
* fix: use prefetch RSC data for PPR * test: add PPR test * feat: warn if ppr is enabled * chore: resolve verification conflict
1 parent 4080e1c commit 8217f50

File tree

11 files changed

+476
-3
lines changed

11 files changed

+476
-3
lines changed
 

‎src/build/content/prerendered.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ const buildPagesCacheValue = async (path: string): Promise<CachedPageValue> => (
4848

4949
const buildAppCacheValue = async (path: string): Promise<CachedPageValue> => {
5050
const meta = JSON.parse(await readFile(`${path}.meta`, 'utf-8'))
51-
const rsc = await readFile(`${path}.rsc`, 'utf-8')
51+
const rsc = await readFile(`${path}.rsc`, 'utf-8').catch(() =>
52+
readFile(`${path}.prefetch.rsc`, 'utf-8'),
53+
)
5254

5355
if (!meta.status && rsc.includes('NEXT_NOT_FOUND')) {
5456
meta.status = 404

‎src/build/verification.ts

+8
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,11 @@ export function verifyNextVersion(ctx: PluginContext, nextVersion: string): void
4141
)
4242
}
4343
}
44+
45+
export function verifyBuildConfig(ctx: PluginContext) {
46+
if (ctx.buildConfig.experimental.ppr) {
47+
console.log(
48+
`Partial prerendering is not yet fully supported on Netlify, see https://ntl.fyi/nextjs-ppr for details`,
49+
)
50+
}
51+
}

‎src/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { createEdgeHandlers } from './build/functions/edge.js'
1212
import { createServerHandler } from './build/functions/server.js'
1313
import { setImageConfig } from './build/image-cdn.js'
1414
import { PluginContext } from './build/plugin-context.js'
15-
import { verifyPublishDir } from './build/verification.js'
15+
import { verifyBuildConfig, verifyPublishDir } from './build/verification.js'
1616

1717
export const onPreBuild = async (options: NetlifyPluginOptions) => {
1818
// Enable Next.js standalone mode at build time
@@ -25,6 +25,7 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
2525
export const onBuild = async (options: NetlifyPluginOptions) => {
2626
const ctx = new PluginContext(options)
2727
verifyPublishDir(ctx)
28+
verifyBuildConfig(ctx)
2829

2930
// only save the build cache if not run via the CLI
3031
if (!options.constants.IS_LOCAL) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const metadata = {
2+
title: 'Simple Next App',
3+
description: 'Description for Simple Next App',
4+
}
5+
6+
export default function RootLayout({ children }) {
7+
return (
8+
<html lang="en">
9+
<body>{children}</body>
10+
</html>
11+
)
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Home() {
2+
return (
3+
<main>
4+
<h1>Home</h1>
5+
<img src="/squirrel.jpg" alt="a cute squirrel" width="300px" />
6+
</main>
7+
)
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
output: 'standalone',
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
},
7+
experimental: {
8+
ppr: true,
9+
},
10+
}
11+
12+
module.exports = nextConfig

0 commit comments

Comments
 (0)
Please sign in to comment.