Skip to content

Commit

Permalink
Ensure next-server prepare only execute once
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 7, 2024
1 parent 070159a commit b2f14a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
let count = 0

export function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
if (count > 0) {
throw new Error('duplicated-register')
}
console.log('register-log')
count++
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { nextTestSetup } from 'e2e-utils'
describe('instrumentation-hook - register-once', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})

if (skipped) {
Expand All @@ -14,4 +13,10 @@ describe('instrumentation-hook - register-once', () => {
await next.fetch('/foo')
expect(next.cliOutput).toIncludeRepeated('register-log', 1)
})

it('should not error when concurrent requests are made', async () => {
await Promise.all([next.fetch('/foo'), next.fetch('/foo')])
expect(next.cliOutput).toIncludeRepeated('register-log', 1)
expect(next.cliOutput).not.toInclude('duplicated-register')
})
})

0 comments on commit b2f14a1

Please sign in to comment.