Skip to content

fix: isolate global dispatcher v2 and add Dispatcher1Wrapper bridge#4827

Merged
mcollina merged 3 commits intonextfrom
fix/global-dispatcher-v2-wrapper
Feb 14, 2026
Merged

fix: isolate global dispatcher v2 and add Dispatcher1Wrapper bridge#4827
mcollina merged 3 commits intonextfrom
fix/global-dispatcher-v2-wrapper

Conversation

@mcollina
Copy link
Member

@mcollina mcollina commented Feb 12, 2026

Summary

  • bump global dispatcher symbol from undici.globalDispatcher.1 to undici.globalDispatcher.2
  • on Node.js 22, mirror setGlobalDispatcher() to undici.globalDispatcher.1 using Dispatcher1Wrapper
  • add Dispatcher1Wrapper to bridge legacy handler callbacks (onConnect/onHeaders/onData/onComplete/onError/onUpgrade) to the new handler API
  • export Dispatcher1Wrapper from index.js and TypeScript declarations
  • add regression tests for global fetch compatibility and Node 22 v1 mirroring
  • add compatibility notes to docs/docs/api/Dispatcher.md

Why

Removing legacy wrappers changed the dispatcher handler interface. Keeping the global symbol at .1 allowed cross-version collisions with Node.js built-in fetch (legacy handler expectations), causing runtime failures like invalid onRequestStart method.

Bumping to .2 isolates Undici's new interface; Node 22 mirroring keeps built-in fetch interoperability by exposing a v1-compatible wrapper.

Tests

  • npx borp -p "test/node-test/global-dispatcher-version.js"
  • /home/matteo/.nvm/versions/node/v22.22.0/bin/npx --yes borp -p "test/node-test/global-dispatcher-version.js"
  • npx borp -p "test/node-test/agent.js"
  • npx borp -p "test/issue-4780.js"
  • npm run lint
  • npm run test:typescript
@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 71.66667% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.18%. Comparing base (393094a) to head (0f6341b).
⚠️ Report is 23 commits behind head on next.

Files with missing lines Patch % Lines
lib/dispatcher/dispatcher1-wrapper.js 75.24% 25 Missing ⚠️
lib/global.js 47.05% 9 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@ ## next #4827 +/- ## ========================================== - Coverage 93.26% 93.18% -0.08%  ========================================== Files 107 108 +1 Lines 34031 34150 +119 ========================================== + Hits 31738 31822 +84  - Misses 2293 2328 +35 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@mcollina
Copy link
Member Author

@mcollina mcollina merged commit 66b08b1 into next Feb 14, 2026
30 of 31 checks passed
@mcollina mcollina deleted the fix/global-dispatcher-v2-wrapper branch February 14, 2026 16:18
@mcollina mcollina mentioned this pull request Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants