Skip to content

Conversation

himself65
Copy link
Member

@himself65 himself65 commented Jul 22, 2025

This relates to...

Rationale

Changes

lazy setup dispatcher so that lazyLoadUndici in node.js core module won't affect the globalThis

Features

Bug Fixes

Fixes: nodejs/node#59012

Breaking Changes and Deprecations

Status

@himself65 himself65 force-pushed the himself65/2025/07/22/global branch 4 times, most recently from 18a7803 to db91409 Compare July 22, 2025 10:08
@mcollina
Copy link
Member

CI doesn't seem happy

@himself65
Copy link
Member Author

Yeah I see, trying to figure out

@himself65 himself65 force-pushed the himself65/2025/07/22/global branch from 2f72fee to ac9a14b Compare August 8, 2025 23:24
@himself65
Copy link
Member Author

@mcollina updated the code

},
set (agent) {
setGlobalDispatcher(agent)
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this implementation is not equivalent. After this change, whoever is reading the dispatcher would invoke a function, which would generate a slight overhead. The solution is on first access to remove all this getter business.

throw new InvalidArgumentError('Argument agent must implement Agent')
}
currentDispatcher = agent
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm relatively certain this function is already available somewhere

@KhafraDev
Copy link
Member

Would it make more sense for undici to always overwrite the global dispatcher (if it's not from undici already)? Importing node:http might not cause issues anymore, but you'd still have these issues the second you used any of the undici-provided globals, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

undici's globalDispatcher missing methods when also importing node:http
5 participants