Skip to content

fix(http_fetcher): use undici.fetch when dispatcher is present#4097

Merged
khassel merged 1 commit intoMagicMirrorOrg:developfrom
KristjanESPERANTO:fix/fetch
Apr 8, 2026
Merged

fix(http_fetcher): use undici.fetch when dispatcher is present#4097
khassel merged 1 commit intoMagicMirrorOrg:developfrom
KristjanESPERANTO:fix/fetch

Conversation

@KristjanESPERANTO
Copy link
Copy Markdown
Collaborator

What's the problem?

The selfSignedCert option passes an undici Agent as dispatcher to fetch(). But Node's built-in fetch() and undici@8's Agent use different internal handler APIs - passing them together throws:

invalid onRequestStart method

What's the fix?

When selfSignedCert is enabled (i.e. a dispatcher is set), use undici's own fetch() instead of the global one. For all other requests, keep using globalThis.fetch.

const fetchFn = requestOptions.dispatcher ? undiciFetch : globalThis.fetch;

Why not just always use undici's fetch?

That would fix the crash - but it would break some tests. MSW (Mock Service Worker), which is used in our test suite to intercept HTTP requests, only hooks into globalThis.fetch. Undici's fetch bypasses those interceptors entirely, so tests would start making real network requests instead of getting the mocked responses. We could rewrite all tests to use undici-compatible mocking instead - but that would be a massive change for no real benefit.


Fixes #4093

Node's built-in fetch() and npm undici@8's Agent have incompatible
internal handler interfaces. Passing an undici Agent as dispatcher
to globalThis.fetch() throws "invalid onRequestStart method".

Use undici.fetch only when a custom dispatcher is set (selfSignedCert),
keeping globalThis.fetch for all other requests.

Fixes MagicMirrorOrg#4093
@khassel khassel merged commit 2e97e29 into MagicMirrorOrg:develop Apr 8, 2026
12 checks passed
@KristjanESPERANTO KristjanESPERANTO deleted the fix/fetch branch April 8, 2026 17:32
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.

2 participants