Skip to content

Commit

Permalink
Fix flying-shuttle full mode breaking instrumentation (#68976)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 16, 2024
1 parent 4d2a793 commit 907d1a6
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1155,9 +1155,10 @@ export default async function getBaseWebpackConfig(
return `static/chunks/[name]-[contenthash].js`
},

path: isNodeServer
? path.join(outputPath, `chunks-${buildId}`)
: outputPath,
path:
!dev && isNodeServer
? path.join(outputPath, `chunks-${buildId}`)
: outputPath,

chunkFilename: isNodeOrEdgeCompilation
? `[name].js`
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/server/web/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export async function getEdgeInstrumentationModule(): Promise<

let instrumentationModulePromise: Promise<any> | null = null
async function registerInstrumentation() {
// Ensure registerInstrumentation is not called in production build
if (process.env.NEXT_PHASE === 'phase-production-build') return
if (!instrumentationModulePromise) {
instrumentationModulePromise = getEdgeInstrumentationModule()
}
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/instrumentation-hook/flying-shuttle/app/edge/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function Page() {
return 'edge'
}

export const runtime = 'edge'
7 changes: 7 additions & 0 deletions test/e2e/instrumentation-hook/flying-shuttle/app/layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Layout({ children }) {
return (
<html>
<body>{children}</body>
</html>
)
}
5 changes: 5 additions & 0 deletions test/e2e/instrumentation-hook/flying-shuttle/app/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function Page() {
return 'node'
}

export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import fs from 'fs-extra'
import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'

describe('instrumentation-hook - flying-shuttle', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})

if (skipped) {
return
}

beforeAll(async () => {
await fs.remove('.next')
})

it('should only register without errors', async () => {
await next.fetch('/')
await next.fetch('/edge')

await retry(() => {
expect(next.cliOutput).toIncludeRepeated('register:edge', 1)
expect(next.cliOutput).not.toContain(
'An error occurred while loading instrumentation hook'
)
expect(next.cliOutput).toIncludeRepeated('register:nodejs', 1)
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function register() {
console.trace('register:' + process.env.NEXT_RUNTIME)
}
11 changes: 11 additions & 0 deletions test/e2e/instrumentation-hook/flying-shuttle/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @type {import('next').NextConfig}
*/
module.exports = {
experimental: {
flyingShuttle: {
mode: 'full',
},
instrumentationHook: true,
},
}

0 comments on commit 907d1a6

Please sign in to comment.