mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
fix: call instrumentationHook earlier for prod server (#63536)
This ensures that the instrumentation hook for Node.js will run immediately during `next start` instead of waiting for the first request like does it `next dev`. However, if there is a separate instrumentation hook for Edge, that will still be lazy evaluated and wait until the first request. Fixes #59999 Fixes NEXT-2738
This commit is contained in:
@@ -252,6 +252,16 @@ export default class NextNodeServer extends BaseServer {
|
||||
}
|
||||
|
||||
this.middlewareManifestPath = join(this.serverDistDir, MIDDLEWARE_MANIFEST)
|
||||
|
||||
// This is just optimization to fire prepare as soon as possible. It will be
|
||||
// properly awaited later. We add the catch here to ensure that it does not
|
||||
// cause a unhandled promise rejection. The promise rejection will be
|
||||
// handled later on via the `await` when the request handler is called.
|
||||
if (!options.dev) {
|
||||
this.prepare().catch((err) => {
|
||||
console.error('Failed to prepare server', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
protected async handleUpgrade(): Promise<void> {
|
||||
|
||||
@@ -67,14 +67,12 @@ describe('Instrumentation Hook', () => {
|
||||
|
||||
describeCase('with-node-api', ({ next }) => {
|
||||
it('with-node-api should run the instrumentation hook', async () => {
|
||||
await next.render('/api')
|
||||
await check(() => next.cliOutput, /instrumentation hook on nodejs/)
|
||||
})
|
||||
})
|
||||
|
||||
describeCase('with-node-page', ({ next }) => {
|
||||
it('with-node-page should run the instrumentation hook', async () => {
|
||||
await next.render('/')
|
||||
await check(() => next.cliOutput, /instrumentation hook on nodejs/)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user