Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/next/src/build/adapter/build-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,9 @@ export async function handleBuildComplete({
)?.routeKeys || {}
const allowQuery = Object.values(routeKeys)
const partialFallback =
// Partial fallback shells are only emitted when Partial Prefetching
// is enabled in the app's Next.js config.
Boolean(config.partialPrefetching) &&
isAppPage &&
remainingPrerenderableParams !== undefined &&
remainingPrerenderableParams.length > 0 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { nextTestSetup } from 'e2e-utils'
import type { NextAdapter } from 'next'

describe('adapter-partial-fallback-disabled', () => {
const { next } = nextTestSetup({
files: __dirname,
})

it('should not emit partial fallback metadata when partialPrefetching is disabled', async () => {
const { outputs }: Parameters<NextAdapter['onBuildComplete']>[0] =
await next.readJSON('build-complete.json')

const withGspPrerender = outputs.prerenders.find(
(output) => output.pathname === '/with-gsp/[slug]'
)
const withGspRouteTreePrerender = outputs.prerenders.find(
(output) =>
output.pathname === '/with-gsp/[slug].segments/_tree.segment.rsc'
)
const withGspOtherSegmentPrerenders = outputs.prerenders.filter(
(output) =>
output.pathname.startsWith('/with-gsp/[slug].segments/') &&
output.pathname !== '/with-gsp/[slug].segments/_tree.segment.rsc'
)

expect(withGspPrerender).toBeDefined()
expect(withGspRouteTreePrerender).toBeDefined()
expect(withGspOtherSegmentPrerenders.length).toBeGreaterThan(0)

// Without `partialPrefetching` enabled, the route that would otherwise
// qualify for a partial fallback shell must not emit the partialFallback
// config, and its fallback shell collapses to the shared shell (empty
// allowQuery).
expect(withGspPrerender.config.partialFallback).toBeUndefined()
expect(withGspPrerender.config.allowQuery).toEqual([])
expect(withGspRouteTreePrerender.config.partialFallback).toBeUndefined()
for (const output of withGspOtherSegmentPrerenders) {
expect(output.config.partialFallback).toBeUndefined()
}
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Loading() {
return <div>loading...</div>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Suspense } from 'react'

async function Dynamic() {
await new Promise((resolve) => setTimeout(resolve, 1000))
return <div>Custom Data</div>
}

export function generateStaticParams() {
return [{ slug: 'one' }]
}

export default async function Page({
params,
}: {
params: Promise<{ slug: string }>
}) {
const { slug } = await params

return (
<div>
<div>{slug}</div>
<Suspense fallback={<div>Loading...</div>}>
<Dynamic />
</Suspense>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import fs from 'fs/promises'

/** @type {import('next').NextAdapter } */
export default {
name: 'adapter-partial-fallback-disabled',
async onBuildComplete(ctx) {
await fs.writeFile('build-complete.json', JSON.stringify(ctx, null, 2))
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
adapterPath: require.resolve('./my-adapter.mjs'),
}

module.exports = nextConfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
const nextConfig = {
cacheComponents: true,
partialPrefetching: true,
adapterPath: require.resolve('./my-adapter.mjs'),
}

Expand Down
Loading