Unverified Commit b6a695bc authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix middleware experimental trace case (#70372)

This ensures we don't overwrite/copy stale middleware chunks with
experimental tracing.
parent 17bdfd8e
...@@ -1776,9 +1776,12 @@ export default async function build( ...@@ -1776,9 +1776,12 @@ export default async function build(
{ {
filter(item) { filter(item) {
// we copy page chunks separately to not copy stale entries // we copy page chunks separately to not copy stale entries
return !item.match(/^[/\\](pages|app)[/\\]/) return (
!item.startsWith('/middleware.js') &&
!item.match(/^[/\\](pages|app)[/\\]/)
)
}, },
overwrite: true, overwrite: false,
} }
) )
} }
......
...@@ -66,11 +66,14 @@ export async function recursiveCopy( ...@@ -66,11 +66,14 @@ export async function recursiveCopy(
// we remove the base path (from) and replace \ by / (windows) // we remove the base path (from) and replace \ by / (windows)
filter(item.replace(from, '').replace(/\\/g, '/')) filter(item.replace(from, '').replace(/\\/g, '/'))
) { ) {
await promises.copyFile( await promises
item, .copyFile(item, target, overwrite ? undefined : COPYFILE_EXCL)
target, .catch((err) => {
overwrite ? undefined : COPYFILE_EXCL // if overwrite is false we shouldn't fail on EEXIST
) if (err.code !== 'EEXIST') {
throw err
}
})
sema.release() sema.release()
} else { } else {
sema.release() sema.release()
......
...@@ -400,5 +400,28 @@ import { nextTestSetup, isNextStart } from 'e2e-utils' ...@@ -400,5 +400,28 @@ import { nextTestSetup, isNextStart } from 'e2e-utils'
await next.patchFile(dataPath, originalDataContent) await next.patchFile(dataPath, originalDataContent)
} }
}) })
it('should have updated middleware on change', async () => {
await next.stop()
const dataPath = 'middleware.js'
const originalDataContent = await next.readFile(dataPath)
try {
await next.patchFile(
dataPath,
originalDataContent.replace(
`'x-flying-shuttle': '1'`,
`'x-flying-shuttle': '2'`
)
)
await nextStart()
const res = await next.fetch('/flying-shuttle')
expect(res.headers.get('x-flying-shuttle')).toBe('2')
} finally {
await next.patchFile(dataPath, originalDataContent)
}
})
} }
) )
...@@ -6,6 +6,14 @@ import { NextResponse } from 'next/server' ...@@ -6,6 +6,14 @@ import { NextResponse } from 'next/server'
* @returns {Promise<NextResponse | undefined>} * @returns {Promise<NextResponse | undefined>}
*/ */
export async function middleware(request) { export async function middleware(request) {
if (request.nextUrl.pathname === '/flying-shuttle') {
return NextResponse.next({
headers: {
'x-flying-shuttle': '1',
},
})
}
if (request.nextUrl.pathname === '/searchparams-normalization-bug') { if (request.nextUrl.pathname === '/searchparams-normalization-bug') {
const headers = new Headers(request.headers) const headers = new Headers(request.headers)
headers.set('test', request.nextUrl.searchParams.get('val') || '') headers.set('test', request.nextUrl.searchParams.get('val') || '')
......
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