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

Add draft mode flag for multi-zone #68997

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions packages/next/src/server/api-utils/node/try-get-preview-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { HeadersAdapter } from '../../web/spec-extension/adapters/headers'
export function tryGetPreviewData(
req: IncomingMessage | BaseNextRequest | Request,
res: ServerResponse | BaseNextResponse,
options: __ApiPreviewProps
options: __ApiPreviewProps,
multiZoneDraftMode: boolean
): PreviewData {
// if an On-Demand revalidation is being done preview mode
// is disabled
Expand Down Expand Up @@ -61,13 +62,17 @@ export function tryGetPreviewData(

// Case: one cookie is set, but not the other.
if (!previewModeId || !tokenPreviewData) {
clearPreviewData(res as NextApiResponse)
if (!multiZoneDraftMode) {
clearPreviewData(res as NextApiResponse)
}
return false
}

// Case: preview session is for an old build.
if (previewModeId !== options.previewModeId) {
clearPreviewData(res as NextApiResponse)
if (!multiZoneDraftMode) {
clearPreviewData(res as NextApiResponse)
}
return false
}

Expand Down
7 changes: 6 additions & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2187,7 +2187,12 @@ export default abstract class Server<
if (process.env.NEXT_RUNTIME !== 'edge') {
const { tryGetPreviewData } =
require('./api-utils/node/try-get-preview-data') as typeof import('./api-utils/node/try-get-preview-data')
previewData = tryGetPreviewData(req, res, this.renderOpts.previewProps)
previewData = tryGetPreviewData(
req,
res,
this.renderOpts.previewProps,
!!this.nextConfig.experimental.multiZoneDraftMode
)
isPreviewMode = previewData !== false
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
linkNoTouchStart: z.boolean().optional(),
manualClientBasePath: z.boolean().optional(),
middlewarePrefetch: z.enum(['strict', 'flexible']).optional(),
multiZoneDraftMode: z.boolean().optional(),
cssChunking: z.enum(['strict', 'loose']).optional(),
nextScriptWorkers: z.boolean().optional(),
// The critter option is unknown, use z.any() here
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export interface LoggingConfig {
}

export interface ExperimentalConfig {
multiZoneDraftMode?: boolean
appNavFailHandling?: boolean
flyingShuttle?: { mode?: 'full' | 'store-only' }
prerenderEarlyExit?: boolean
Expand Down Expand Up @@ -979,6 +980,7 @@ export const defaultConfig: NextConfig = {
modularizeImports: undefined,
outputFileTracingRoot: process.env.NEXT_PRIVATE_OUTPUT_TRACE_ROOT || '',
experimental: {
multiZoneDraftMode: false,
appNavFailHandling: Boolean(process.env.NEXT_PRIVATE_FLYING_SHUTTLE),
flyingShuttle: Boolean(process.env.NEXT_PRIVATE_FLYING_SHUTTLE)
? {
Expand Down
Loading