Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flying-shuttle full mode breaking instrumentation #68976

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
}
Loading