Unverified Commit 2b5d62dc authored by Gerald Monaco's avatar Gerald Monaco Committed by GitHub

Stop using environment variables in `pages/_document` (#31946)

Since #31939 is going to move the `Document` components, we can't rely on `DefinePlugin` to provide environment variables. This PR passes them as render opts instead. We can't just force this to be bundled like e.g. `next/dynamic`, because we use it internally.
parent 12b44e27
...@@ -191,6 +191,10 @@ export function getPageHandler(ctx: ServerlessHandlerCtx) { ...@@ -191,6 +191,10 @@ export function getPageHandler(ctx: ServerlessHandlerCtx) {
locale: detectedLocale, locale: detectedLocale,
defaultLocale, defaultLocale,
domainLocales: i18n?.domains, domainLocales: i18n?.domains,
optimizeImages: process.env.__NEXT_OPTIMIZE_IMAGES,
optimizeCss: process.env.__NEXT_OPTIMIZE_CSS,
concurrentFeatures: process.env.__NEXT_CONCURRENT_FEATURES,
crossOrigin: process.env.__NEXT_CROSS_ORIGIN,
}, },
options options
) )
......
...@@ -381,6 +381,10 @@ export default async function exportApp( ...@@ -381,6 +381,10 @@ export default async function exportApp(
// Exported pages do not currently support dynamic HTML. // Exported pages do not currently support dynamic HTML.
supportsDynamicHTML: false, supportsDynamicHTML: false,
concurrentFeatures: nextConfig.experimental.concurrentFeatures, concurrentFeatures: nextConfig.experimental.concurrentFeatures,
crossOrigin: nextConfig.crossOrigin,
optimizeCss: nextConfig.experimental.optimizeCss,
optimizeFonts: nextConfig.optimizeFonts,
optimizeImages: nextConfig.experimental.optimizeImages,
} }
const { serverRuntimeConfig, publicRuntimeConfig } = nextConfig const { serverRuntimeConfig, publicRuntimeConfig } = nextConfig
......
This diff is collapsed.
...@@ -206,6 +206,7 @@ export default class Server { ...@@ -206,6 +206,7 @@ export default class Server {
domainLocales?: DomainLocale[] domainLocales?: DomainLocale[]
distDir: string distDir: string
concurrentFeatures?: boolean concurrentFeatures?: boolean
crossOrigin?: string
} }
private compression?: ExpressMiddleware private compression?: ExpressMiddleware
private incrementalCache: IncrementalCache private incrementalCache: IncrementalCache
...@@ -275,6 +276,9 @@ export default class Server { ...@@ -275,6 +276,9 @@ export default class Server {
domainLocales: this.nextConfig.i18n?.domains, domainLocales: this.nextConfig.i18n?.domains,
distDir: this.distDir, distDir: this.distDir,
concurrentFeatures: this.nextConfig.experimental.concurrentFeatures, concurrentFeatures: this.nextConfig.experimental.concurrentFeatures,
crossOrigin: this.nextConfig.crossOrigin
? this.nextConfig.crossOrigin
: undefined,
} }
// Only the `publicRuntimeConfig` key is exposed to the client side // Only the `publicRuntimeConfig` key is exposed to the client side
......
...@@ -218,6 +218,7 @@ export type RenderOptsPartial = { ...@@ -218,6 +218,7 @@ export type RenderOptsPartial = {
supportsDynamicHTML?: boolean supportsDynamicHTML?: boolean
concurrentFeatures?: boolean concurrentFeatures?: boolean
customServer?: boolean customServer?: boolean
crossOrigin?: string
} }
export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial export type RenderOpts = LoadComponentsReturnType & RenderOptsPartial
...@@ -1297,6 +1298,11 @@ export async function renderToHTML( ...@@ -1297,6 +1298,11 @@ export async function renderToHTML(
styles: documentResult.styles, styles: documentResult.styles,
useMainContent: documentResult.useMainContent, useMainContent: documentResult.useMainContent,
useMaybeDeferContent, useMaybeDeferContent,
crossOrigin: renderOpts.crossOrigin,
optimizeCss: renderOpts.optimizeCss,
optimizeFonts: renderOpts.optimizeFonts,
optimizeImages: renderOpts.optimizeImages,
concurrentFeatures: renderOpts.concurrentFeatures,
} }
const document = ( const document = (
......
...@@ -222,6 +222,11 @@ export type HtmlProps = { ...@@ -222,6 +222,11 @@ export type HtmlProps = {
head?: Array<JSX.Element | null> head?: Array<JSX.Element | null>
useMaybeDeferContent: MaybeDeferContentHook useMaybeDeferContent: MaybeDeferContentHook
useMainContent: (fn?: (content: JSX.Element) => JSX.Element) => JSX.Element useMainContent: (fn?: (content: JSX.Element) => JSX.Element) => JSX.Element
crossOrigin?: string
optimizeCss?: boolean
optimizeFonts?: boolean
optimizeImages?: boolean
concurrentFeatures?: boolean
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment