Unverified Commit 17033ca9 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Less dynamic pages manifest path (#90581)

_Two steps forward, one step back_

Reverts https://github.com/vercel/next.js/pull/88641 and https://github.com/vercel/next.js/pull/88806

I ended up having to keep the build id in `_next/data` routes anyway (and made the id a constant if skew protection is enabled). This was because it was utterly impossible to change the routes from `_next/data/:buildId/*` to `_next/data/*` in the builder in a backwards-compatible way.

So there is no need to remove the build id from `_next/static` here either. It just makes testing a huge pain because the paths keep changing
parent 05b06903
...@@ -548,12 +548,10 @@ async function writeClientSsgManifest( ...@@ -548,12 +548,10 @@ async function writeClientSsgManifest(
buildId, buildId,
distDir, distDir,
locales, locales,
deploymentId,
}: { }: {
buildId: string buildId: string
distDir: string distDir: string
locales: readonly string[] | undefined locales: readonly string[] | undefined
deploymentId: string
} }
) { ) {
const ssgPages = new Set<string>( const ssgPages = new Set<string>(
...@@ -570,12 +568,11 @@ async function writeClientSsgManifest( ...@@ -570,12 +568,11 @@ async function writeClientSsgManifest(
ssgPages ssgPages
)};self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()` )};self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()`
// When skew protection is enabled, we instead just rely on the deployment id query string to let ssgManifestPath = path.join(
// load the correct manifests, to avoid the build id. CLIENT_STATIC_FILES_PATH,
let ssgManifestPath = deploymentId buildId,
? path.join(CLIENT_STATIC_FILES_PATH, '_ssgManifest.js') '_ssgManifest.js'
: path.join(CLIENT_STATIC_FILES_PATH, buildId, '_ssgManifest.js') )
await writeFileUtf8( await writeFileUtf8(
path.join(distDir, ssgManifestPath), path.join(distDir, ssgManifestPath),
clientSsgManifestContent clientSsgManifestContent
...@@ -2591,12 +2588,7 @@ export default async function build( ...@@ -2591,12 +2588,7 @@ export default async function build(
2 2
)};self.__MIDDLEWARE_MATCHERS_CB && self.__MIDDLEWARE_MATCHERS_CB()` )};self.__MIDDLEWARE_MATCHERS_CB && self.__MIDDLEWARE_MATCHERS_CB()`
let clientMiddlewareManifestPath = config.deploymentId let clientMiddlewareManifestPath = path.join(
? path.join(
CLIENT_STATIC_FILES_PATH,
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST
)
: path.join(
CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_PATH,
buildId, buildId,
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST
...@@ -3959,7 +3951,6 @@ export default async function build( ...@@ -3959,7 +3951,6 @@ export default async function build(
distDir, distDir,
buildId, buildId,
locales: config.i18n?.locales, locales: config.i18n?.locales,
deploymentId: config.deploymentId,
}) })
} else { } else {
await writePrerenderManifest(distDir, { await writePrerenderManifest(distDir, {
......
...@@ -143,11 +143,9 @@ export async function turbopackBuild(): Promise<{ ...@@ -143,11 +143,9 @@ export async function turbopackBuild(): Promise<{
await fs.writeFile(path.join(distDir, 'turbopack'), '') await fs.writeFile(path.join(distDir, 'turbopack'), '')
await fs.mkdir(path.join(distDir, 'server'), { recursive: true }) await fs.mkdir(path.join(distDir, 'server'), { recursive: true })
if (!config.deploymentId) {
await fs.mkdir(path.join(distDir, 'static', buildId), { await fs.mkdir(path.join(distDir, 'static', buildId), {
recursive: true, recursive: true,
}) })
}
await fs.writeFile( await fs.writeFile(
path.join(distDir, 'package.json'), path.join(distDir, 'package.json'),
'{"type": "commonjs"}' '{"type": "commonjs"}'
...@@ -181,7 +179,6 @@ export async function turbopackBuild(): Promise<{ ...@@ -181,7 +179,6 @@ export async function turbopackBuild(): Promise<{
distDir, distDir,
encryptionKey, encryptionKey,
dev: false, dev: false,
deploymentId: config.deploymentId,
sriEnabled, sriEnabled,
}) })
......
...@@ -2127,8 +2127,6 @@ export default async function getBaseWebpackConfig( ...@@ -2127,8 +2127,6 @@ export default async function getBaseWebpackConfig(
isClient && isClient &&
new BuildManifestPlugin({ new BuildManifestPlugin({
buildId, buildId,
dev,
deploymentId: config.deploymentId,
rewrites, rewrites,
isDevFallback, isDevFallback,
appDirEnabled: hasAppDir, appDirEnabled: hasAppDir,
......
...@@ -27,20 +27,8 @@ import { ...@@ -27,20 +27,8 @@ import {
type DeepMutable<T> = { -readonly [P in keyof T]: DeepMutable<T[P]> } type DeepMutable<T> = { -readonly [P in keyof T]: DeepMutable<T[P]> }
// nodejs: '/static/<build id>/low-priority.js' function buildNodejsLowPriorityPath(filename: string, buildId: string) {
// or with skew protection: '/static/low-priority.js'
function buildNodejsLowPriorityPath(
filename: string,
buildId: string,
dev: boolean,
deploymentId: string
) {
if (!dev && deploymentId) {
// Leverage skew protection
return `${CLIENT_STATIC_FILES_PATH}/${filename}`
} else {
return `${CLIENT_STATIC_FILES_PATH}/${buildId}/${filename}` return `${CLIENT_STATIC_FILES_PATH}/${buildId}/${filename}`
}
} }
// This function takes the asset map generated in BuildManifestPlugin and creates a // This function takes the asset map generated in BuildManifestPlugin and creates a
...@@ -113,8 +101,6 @@ export function getEntrypointFiles(entrypoint: any): string[] { ...@@ -113,8 +101,6 @@ export function getEntrypointFiles(entrypoint: any): string[] {
// It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production // It has a mapping of "entry" filename to real filename. Because the real filename can be hashed in production
export default class BuildManifestPlugin { export default class BuildManifestPlugin {
private buildId: string private buildId: string
private dev: boolean
private deploymentId: string
private rewrites: CustomRoutes['rewrites'] private rewrites: CustomRoutes['rewrites']
private isDevFallback: boolean private isDevFallback: boolean
private appDirEnabled: boolean private appDirEnabled: boolean
...@@ -122,16 +108,12 @@ export default class BuildManifestPlugin { ...@@ -122,16 +108,12 @@ export default class BuildManifestPlugin {
constructor(options: { constructor(options: {
buildId: string buildId: string
dev: boolean
deploymentId: string
rewrites: CustomRoutes['rewrites'] rewrites: CustomRoutes['rewrites']
isDevFallback?: boolean isDevFallback?: boolean
appDirEnabled: boolean appDirEnabled: boolean
clientRouterFilters?: Parameters<typeof generateClientManifest>[2] clientRouterFilters?: Parameters<typeof generateClientManifest>[2]
}) { }) {
this.buildId = options.buildId this.buildId = options.buildId
this.dev = options.dev
this.deploymentId = options.deploymentId
this.isDevFallback = !!options.isDevFallback this.isDevFallback = !!options.isDevFallback
this.rewrites = { this.rewrites = {
beforeFiles: [], beforeFiles: [],
...@@ -223,15 +205,11 @@ export default class BuildManifestPlugin { ...@@ -223,15 +205,11 @@ export default class BuildManifestPlugin {
// downloaded by the client. // downloaded by the client.
const buildManifestPath = buildNodejsLowPriorityPath( const buildManifestPath = buildNodejsLowPriorityPath(
'_buildManifest.js', '_buildManifest.js',
this.buildId, this.buildId
this.dev,
this.deploymentId
) )
const ssgManifestPath = buildNodejsLowPriorityPath( const ssgManifestPath = buildNodejsLowPriorityPath(
'_ssgManifest.js', '_ssgManifest.js',
this.buildId, this.buildId
this.dev,
this.deploymentId
) )
assetMap.lowPriorityFiles.push(buildManifestPath, ssgManifestPath) assetMap.lowPriorityFiles.push(buildManifestPath, ssgManifestPath)
compilation.emitAsset( compilation.emitAsset(
...@@ -267,9 +245,7 @@ export default class BuildManifestPlugin { ...@@ -267,9 +245,7 @@ export default class BuildManifestPlugin {
if (!this.isDevFallback) { if (!this.isDevFallback) {
const buildManifestPath = buildNodejsLowPriorityPath( const buildManifestPath = buildNodejsLowPriorityPath(
'_buildManifest.js', '_buildManifest.js',
this.buildId, this.buildId
this.dev,
this.deploymentId
) )
compilation.emitAsset( compilation.emitAsset(
buildManifestPath, buildManifestPath,
......
...@@ -449,7 +449,6 @@ export async function createHotReloaderTurbopack( ...@@ -449,7 +449,6 @@ export async function createHotReloaderTurbopack(
distDir, distDir,
encryptionKey, encryptionKey,
dev: true, dev: true,
deploymentId: nextConfig.deploymentId,
sriEnabled: false, sriEnabled: false,
}) })
......
...@@ -212,7 +212,6 @@ export class TurbopackManifestLoader { ...@@ -212,7 +212,6 @@ export class TurbopackManifestLoader {
private readonly distDir: string private readonly distDir: string
private readonly buildId: string private readonly buildId: string
private readonly deploymentId: string
private readonly dev: boolean private readonly dev: boolean
private readonly sriEnabled: boolean private readonly sriEnabled: boolean
...@@ -221,21 +220,18 @@ export class TurbopackManifestLoader { ...@@ -221,21 +220,18 @@ export class TurbopackManifestLoader {
buildId, buildId,
encryptionKey, encryptionKey,
dev, dev,
deploymentId,
sriEnabled, sriEnabled,
}: { }: {
buildId: string buildId: string
distDir: string distDir: string
encryptionKey: string encryptionKey: string
dev: boolean dev: boolean
deploymentId: string
sriEnabled: boolean sriEnabled: boolean
}) { }) {
this.distDir = distDir this.distDir = distDir
this.buildId = buildId this.buildId = buildId
this.encryptionKey = encryptionKey this.encryptionKey = encryptionKey
this.dev = dev this.dev = dev
this.deploymentId = deploymentId
this.sriEnabled = sriEnabled this.sriEnabled = sriEnabled
} }
...@@ -641,25 +637,16 @@ export class TurbopackManifestLoader { ...@@ -641,25 +637,16 @@ export class TurbopackManifestLoader {
const sortedPageKeys = getSortedRoutes(pagesKeys) const sortedPageKeys = getSortedRoutes(pagesKeys)
let buildManifestPath let buildManifestPath = join(
let ssgManifestPath
if (this.deploymentId && !this.dev) {
// When skew protection is enabled, we instead just rely on the deployment id query string to
// load the correct manifests, to avoid the build id.
buildManifestPath = join(CLIENT_STATIC_FILES_PATH, '_buildManifest.js')
ssgManifestPath = join(CLIENT_STATIC_FILES_PATH, '_ssgManifest.js')
} else {
buildManifestPath = join(
CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_PATH,
this.buildId, this.buildId,
'_buildManifest.js' '_buildManifest.js'
) )
ssgManifestPath = join( let ssgManifestPath = join(
CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_PATH,
this.buildId, this.buildId,
'_ssgManifest.js' '_ssgManifest.js'
) )
}
if ( if (
this.dev && this.dev &&
...@@ -850,10 +837,7 @@ export class TurbopackManifestLoader { ...@@ -850,10 +837,7 @@ export class TurbopackManifestLoader {
private writeMiddlewareManifest(): { private writeMiddlewareManifest(): {
clientMiddlewareManifestPath: string clientMiddlewareManifestPath: string
} { } {
let clientMiddlewareManifestPath = let clientMiddlewareManifestPath = join(
this.deploymentId && !this.dev
? join(CLIENT_STATIC_FILES_PATH, TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST)
: join(
CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_PATH,
this.buildId, this.buildId,
TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST TURBOPACK_CLIENT_MIDDLEWARE_MANIFEST
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-app-asset-prefix', () => { describe('invalid-static-asset-404-app-asset-prefix', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
assetPrefix: '/assets', assetPrefix: '/assets',
...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-app-asset-prefix', () => { ...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-app-asset-prefix', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = isNextDeploy const buildManifestPath = `/assets/_next/static/${next.buildId}/_buildManifest.js`
? '/assets/_next/static/_buildManifest.js'
: `/assets/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-app-base-path', () => { describe('invalid-static-asset-404-app-base-path', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
basePath: '/base', basePath: '/base',
...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-app-base-path', () => { ...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-app-base-path', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = isNextDeploy const buildManifestPath = `/base/_next/static/${next.buildId}/_buildManifest.js`
? '/base/_next/static/_buildManifest.js'
: `/base/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-app', () => { describe('invalid-static-asset-404-app', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = isNextDeploy const buildManifestPath = `/_next/static/${next.buildId}/_buildManifest.js`
? '/_next/static/_buildManifest.js'
: `/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-pages-asset-prefix', () => { describe('invalid-static-asset-404-pages-asset-prefix', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
assetPrefix: '/assets', assetPrefix: '/assets',
...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-pages-asset-prefix', () => { ...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-pages-asset-prefix', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = isNextDeploy const buildManifestPath = `/assets/_next/static/${next.buildId}/_buildManifest.js`
? '/assets/_next/static/_buildManifest.js'
: `/assets/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-pages-base-path', () => { describe('invalid-static-asset-404-pages-base-path', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
nextConfig: { nextConfig: {
basePath: '/base', basePath: '/base',
...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-pages-base-path', () => { ...@@ -9,9 +9,7 @@ describe('invalid-static-asset-404-pages-base-path', () => {
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = isNextDeploy const buildManifestPath = `/base/_next/static/${next.buildId}/_buildManifest.js`
? '/base/_next/static/_buildManifest.js'
: `/base/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
describe('invalid-static-asset-404-pages', () => { describe('invalid-static-asset-404-pages', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should return correct output with status 200 on valid asset path', async () => { it('should return correct output with status 200 on valid asset path', async () => {
const buildManifestPath = isNextDeploy const buildManifestPath = `/_next/static/${next.buildId}/_buildManifest.js`
? '/_next/static/_buildManifest.js'
: `/_next/static/${next.buildId}/_buildManifest.js`
const res = await next.fetch(buildManifestPath) const res = await next.fetch(buildManifestPath)
expect(res.status).toBe(200) expect(res.status).toBe(200)
......
...@@ -48,7 +48,7 @@ describe('Middleware custom matchers i18n', () => { ...@@ -48,7 +48,7 @@ describe('Middleware custom matchers i18n', () => {
}) })
describe('Middleware custom matchers with root', () => { describe('Middleware custom matchers with root', () => {
const { next, isNextDeploy } = nextTestSetup({ const { next } = nextTestSetup({
files: { files: {
pages: new FileRef(join(__dirname, '../app', 'pages')), pages: new FileRef(join(__dirname, '../app', 'pages')),
'next.config.js': new FileRef( 'next.config.js': new FileRef(
...@@ -76,9 +76,7 @@ describe('Middleware custom matchers with root', () => { ...@@ -76,9 +76,7 @@ describe('Middleware custom matchers with root', () => {
it('should not match', async () => { it('should not match', async () => {
const res = await next.fetch( const res = await next.fetch(
isNextDeploy `/_next/static/${next.buildId}/_buildManifest.js`
? '/_next/static/_buildManifest.js'
: `/_next/static/${next.buildId}/_buildManifest.js`
) )
expect(res.status).toBe(200) expect(res.status).toBe(200)
expect(res.headers.get('x-from-middleware')).toBeFalsy() expect(res.headers.get('x-from-middleware')).toBeFalsy()
......
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