diff --git a/packages/next/src/build/webpack-config.ts b/packages/next/src/build/webpack-config.ts index 80516c7703beb7..73acdfd1938f67 100644 --- a/packages/next/src/build/webpack-config.ts +++ b/packages/next/src/build/webpack-config.ts @@ -251,6 +251,12 @@ export function getDefineEnv({ 'process.env.NEXT_RUNTIME': JSON.stringify( isEdgeServer ? 'edge' : isNodeServer ? 'nodejs' : undefined ), + 'process.env.__NEXT_ACTIONS_DEPLOYMENT_ID': JSON.stringify( + config.experimental.useDeploymentIdServerActions + ), + 'process.env.__NEXT_DEPLOYMENT_ID': JSON.stringify( + config.experimental.deploymentId + ), 'process.env.__NEXT_FETCH_CACHE_KEY_PREFIX': JSON.stringify(fetchCacheKeyPrefix), 'process.env.__NEXT_PREVIEW_MODE_ID': JSON.stringify(previewModeId), diff --git a/packages/next/src/client/app-index.tsx b/packages/next/src/client/app-index.tsx index 856f21b0d844c8..113268c970b093 100644 --- a/packages/next/src/client/app-index.tsx +++ b/packages/next/src/client/app-index.tsx @@ -45,7 +45,14 @@ const chunkFilenameMap: any = {} // eslint-disable-next-line no-undef __webpack_require__.u = (chunkId: any) => { - return encodeURI(chunkFilenameMap[chunkId] || getChunkScriptFilename(chunkId)) + return ( + encodeURI(chunkFilenameMap[chunkId] || getChunkScriptFilename(chunkId)) + + `${ + process.env.__NEXT_DEPLOYMENT_ID + ? `?dpl=${process.env.__NEXT_DEPLOYMENT_ID}` + : '' + }` + ) } // Ignore the module ID transform in client. diff --git a/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts b/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts index 2a5f7e16bead89..27dc7b4cd7a078 100644 --- a/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts +++ b/packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts @@ -44,6 +44,12 @@ async function fetchServerAction( Accept: RSC_CONTENT_TYPE_HEADER, 'Next-Action': actionId, [NEXT_ROUTER_STATE_TREE]: JSON.stringify(state.tree), + ...(process.env.__NEXT_ACTIONS_DEPLOYMENT_ID && + process.env.__NEXT_DEPLOYMENT_ID + ? { + 'x-deployment-id': process.env.__NEXT_DEPLOYMENT_ID, + } + : {}), ...(state.nextUrl ? { [NEXT_URL]: state.nextUrl, diff --git a/packages/next/src/client/route-loader.ts b/packages/next/src/client/route-loader.ts index 9365e899acfc68..d40b5a8b3fbdd8 100644 --- a/packages/next/src/client/route-loader.ts +++ b/packages/next/src/client/route-loader.ts @@ -106,6 +106,12 @@ function hasPrefetch(link?: HTMLLinkElement): boolean { const canPrefetch: boolean = hasPrefetch() +const getAssetQueryString = () => { + return process.env.__NEXT_DEPLOYMENT_ID + ? `?dpl=${process.env.__NEXT_DEPLOYMENT_ID}` + : '' +} + function prefetchViaDom( href: string, as: string, @@ -246,7 +252,8 @@ function getFilesForRoute( const scriptUrl = assetPrefix + '/_next/static/chunks/pages' + - encodeURI(getAssetPathFromRoute(route, '.js')) + encodeURI(getAssetPathFromRoute(route, '.js')) + + getAssetQueryString() return Promise.resolve({ scripts: [__unsafeCreateTrustedScriptURL(scriptUrl)], // Styles are handled by `style-loader` in development: @@ -263,8 +270,10 @@ function getFilesForRoute( return { scripts: allFiles .filter((v) => v.endsWith('.js')) - .map((v) => __unsafeCreateTrustedScriptURL(v)), - css: allFiles.filter((v) => v.endsWith('.css')), + .map((v) => __unsafeCreateTrustedScriptURL(v) + getAssetQueryString()), + css: allFiles + .filter((v) => v.endsWith('.css')) + .map((v) => v + getAssetQueryString()), } }) } diff --git a/packages/next/src/export/index.ts b/packages/next/src/export/index.ts index 0adfb2019d2a24..6c6fd3a85e458d 100644 --- a/packages/next/src/export/index.ts +++ b/packages/next/src/export/index.ts @@ -493,6 +493,7 @@ export default async function exportApp( } : {}), strictNextHead: !!nextConfig.experimental.strictNextHead, + deploymentId: nextConfig.experimental.deploymentId, } const { serverRuntimeConfig, publicRuntimeConfig } = nextConfig diff --git a/packages/next/src/export/worker.ts b/packages/next/src/export/worker.ts index 1e82c503a2d0b0..312ff2f0f9f90d 100644 --- a/packages/next/src/export/worker.ts +++ b/packages/next/src/export/worker.ts @@ -119,6 +119,7 @@ interface RenderOpts { incrementalCache?: IncrementalCache strictNextHead?: boolean originalPathname?: string + deploymentId?: string } export default async function exportPage({ @@ -155,6 +156,9 @@ export default async function exportPage({ } try { + if (renderOpts.deploymentId) { + process.env.__NEXT_DEPLOYMENT_ID = renderOpts.deploymentId + } const { query: originalQuery = {} } = pathMap const { page } = pathMap const pathname = normalizeAppPath(page) diff --git a/packages/next/src/pages/_document.tsx b/packages/next/src/pages/_document.tsx index 39198ec196ffb8..48a845299b1098 100644 --- a/packages/next/src/pages/_document.tsx +++ b/packages/next/src/pages/_document.tsx @@ -68,7 +68,7 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) { const { assetPrefix, buildManifest, - devOnlyCacheBusterQueryString, + assetQueryString, disableOptimizedLoading, crossOrigin, } = context @@ -84,7 +84,7 @@ function getPolyfillScripts(context: HtmlProps, props: OriginProps) { nonce={props.nonce} crossOrigin={props.crossOrigin || crossOrigin} noModule={true} - src={`${assetPrefix}/_next/${polyfill}${devOnlyCacheBusterQueryString}`} + src={`${assetPrefix}/_next/${polyfill}${assetQueryString}`} /> )) } @@ -146,7 +146,7 @@ function getDynamicChunks( dynamicImports, assetPrefix, isDevelopment, - devOnlyCacheBusterQueryString, + assetQueryString, disableOptimizedLoading, crossOrigin, } = context @@ -159,9 +159,7 @@ function getDynamicChunks( async={!isDevelopment && disableOptimizedLoading} defer={!disableOptimizedLoading} key={file} - src={`${assetPrefix}/_next/${encodeURI( - file - )}${devOnlyCacheBusterQueryString}`} + src={`${assetPrefix}/_next/${encodeURI(file)}${assetQueryString}`} nonce={props.nonce} crossOrigin={props.crossOrigin || crossOrigin} /> @@ -178,7 +176,7 @@ function getScripts( assetPrefix, buildManifest, isDevelopment, - devOnlyCacheBusterQueryString, + assetQueryString, disableOptimizedLoading, crossOrigin, } = context @@ -192,9 +190,7 @@ function getScripts( return (