Skip to content

Conversation

@jgeschwendt
Copy link

@jgeschwendt jgeschwendt commented Jan 9, 2026

What?

Capture setImmediate[promisify.custom] at module initialization instead of lazily accessing it when needed.

    RangeError: Maximum call stack size exceeded

      at patchedSetImmediatePromise (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/node-environment-extensions/fast-set-immediate.external.ts:626:27)
      at originalPromisify (node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/next/src/server/node-environment-extensions/fast-set-immediate.external.ts:627:12)

This was discovered upgrading from 16.0.10 to 16.1.0

Why?

When util.promisify(setImmediate) is called and currentExecution === null, the code was accessing originalSetImmediate[promisify.custom] at call time. However, promisify.custom can get lost or return undefined after the module patches setImmediate, causing promisify(setImmediate) to fail. Specifically, when used with jest.

Reproduction: https://github.com/jgeschwendt/nextjs-setimmediate-promisify-repro

How?

Move the capture of originalSetImmediate[promisify.custom] to module initialization time (alongside originalSetImmediate, originalClearImmediate, and originalNextTick), ensuring the original promisified implementation is preserved before any patching occurs.

@nextjs-bot
Copy link
Collaborator

nextjs-bot commented Jan 9, 2026

Allow CI Workflow Run

  • approve CI run for commit: 4b8ae56

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@vercel vercel deleted a comment from nextjs-bot Jan 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants