Unverified Commit abe74a52 authored by Steven's avatar Steven Committed by GitHub

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
parent 39340ab4
......@@ -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/)
})
})
......
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