Skip to content

Commit c83e75d

Browse files
committed
fix: don't fail on dynamic routes when PPR is enabled
1 parent d64e3fb commit c83e75d

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

src/build/plugin-context.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import type {
1010
NetlifyPluginOptions,
1111
NetlifyPluginUtils,
1212
} from '@netlify/build'
13-
import type { PrerenderManifest, RoutesManifest } from 'next/dist/build/index.js'
1413
import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middleware-plugin.js'
1514
import type { PagesManifest } from 'next/dist/build/webpack/plugins/pages-manifest-plugin.js'
1615
import type { NextConfigComplete } from 'next/dist/server/config-shared.js'
17-
import type { FunctionsConfigManifest } from 'next-with-cache-handler-v2/dist/build/index.js'
16+
import type {
17+
FunctionsConfigManifest,
18+
PrerenderManifest,
19+
RoutesManifest,
20+
} from 'next-with-cache-handler-v2/dist/build/index.js'
1821
import { satisfies } from 'semver'
1922

2023
const MODULE_DIR = fileURLToPath(new URL('.', import.meta.url))
@@ -374,7 +377,7 @@ export class PluginContext {
374377
// - `string` - when user use pages router with `fallback: true`, and then it's html file path
375378
// - `null` - when user use pages router with `fallback: 'block'` or app router with `export const dynamicParams = true`
376379
// - `false` - when user use pages router with `fallback: false` or app router with `export const dynamicParams = false`
377-
if (typeof meta.fallback === 'string') {
380+
if (typeof meta.fallback === 'string' && meta.renderingMode !== 'PARTIALLY_STATIC') {
378381
for (const locale of locales) {
379382
const localizedRoute = posixJoin(locale, route.replace(/^\/+/g, ''))
380383
fallbacks.push(localizedRoute)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Suspense } from 'react'
2+
import { connection } from 'next/server'
3+
4+
export async function generateStaticParams() {
5+
return [{ dynamic: '1' }, { dynamic: '2' }]
6+
}
7+
8+
async function getData(params) {
9+
await connection()
10+
const res = await fetch(`https://api.tvmaze.com/shows/${params.id}`, {
11+
next: {
12+
tags: [`show-${params.id}`],
13+
},
14+
})
15+
await new Promise((res) => setTimeout(res, 3000))
16+
return res.json()
17+
}
18+
19+
async function Content(params) {
20+
const data = await getData(params)
21+
22+
return (
23+
<dl>
24+
<dt>Show</dt>
25+
<dd>{data.name}</dd>
26+
<dt>Param</dt>
27+
<dd>{params.id}</dd>
28+
<dt>Time</dt>
29+
<dd data-testid="date-now">{new Date().toISOString()}</dd>
30+
</dl>
31+
)
32+
}
33+
34+
export default async function DynamicPage({ params }) {
35+
const { dynamic } = await params
36+
37+
return (
38+
<main>
39+
<h1>Dynamic Page: {dynamic}</h1>
40+
<Suspense fallback={<div>loading...</div>}>
41+
<Content id={dynamic} />
42+
</Suspense>
43+
</main>
44+
)
45+
}

tests/integration/simple-app.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ test.skipIf(process.env.NEXT_VERSION !== 'canary')<FixtureTestContext>(
394394
const blobEntries = await getBlobEntries(ctx)
395395
expect(blobEntries.map(({ key }) => decodeBlobKey(key)).sort()).toEqual(
396396
[
397+
'/1',
398+
'/2',
397399
'/404',
398400
shouldHaveAppRouterGlobalErrorInPrerenderManifest() ? '/_global-error' : undefined,
399401
shouldHaveAppRouterNotFoundInPrerenderManifest() ? '/_not-found' : undefined,
@@ -407,6 +409,14 @@ test.skipIf(process.env.NEXT_VERSION !== 'canary')<FixtureTestContext>(
407409
const home = await invokeFunction(ctx)
408410
expect(home.statusCode).toBe(200)
409411
expect(load(home.body)('h1').text()).toBe('Home')
412+
413+
const dynamicPrerendered = await invokeFunction(ctx, { url: '/1' })
414+
expect(dynamicPrerendered.statusCode).toBe(200)
415+
expect(load(dynamicPrerendered.body)('h1').text()).toBe('Dynamic Page: 1')
416+
417+
const dynamicNotPrerendered = await invokeFunction(ctx, { url: '/3' })
418+
expect(dynamicNotPrerendered.statusCode).toBe(200)
419+
expect(load(dynamicNotPrerendered.body)('h1').text()).toBe('Dynamic Page: 3')
410420
},
411421
)
412422

0 commit comments

Comments
 (0)