mswjs / interceptors

Low-level network interception library.
https://npm.im/@mswjs/interceptors
MIT License
537 stars 123 forks source link

v0.33.1 breaks Remix applications using polyfills in NodeJs #649

Closed MattyBalaam closed 48 minutes ago

MattyBalaam commented 2 hours ago

After upgrading from msw v2.4.3 to v2.4.4 our remix apps using MSW started failing with no data being returned from remix loaders.

I then narrowed it down to a change in @mswjs/interceptors from v0.33.0 to v0.33.1

I am not sure exactly what the issue is, but after comparing the changes, I have been able to stop the regression by removing a call to recordRawFetchHeaders

Screenshot 2024-10-01 at 14 16 41

This was added here: https://github.com/mswjs/interceptors/commit/4660558f27e610063ff204ccf4a7595082040a0b#diff-58118abd89f14c6d555b9972de91edd6eeca4ccb3bd73ce0724bc9af9d595281

I have narrowed this down further to us using Remix’s installGlobals in our vite config - we can’t use the node build-in fetch in our case because we need to use the host header

MattyBalaam commented 2 hours ago

I have attempted to replace using installGlobals by adding undici and directly importing their fetch implementation

Do you think the issue might be with them?

MattyBalaam commented 1 hour ago

Some more digging, If I go into the remix code which enables specific polyfills they replace global.Headers in Node with this: https://github.com/remix-run/web-std-io/blob/main/packages/fetch/src/headers.js

kettanaito commented 1 hour ago

Hi. Thanks for reporting this. I believe this has been addressed. Could you please update to the latest version of the package and let me know?

MattyBalaam commented 1 hour ago

It was actually the bump up to MSW v2.4.9 which showed the issue, but I narrowed down the issue to starting with v2.4.4

I just forced @mswjs/interceptors to 0.36.0 (using msw v2.4.9 ) with yarn resolutions but the issue persists.

kettanaito commented 48 minutes ago

Gotcha. Then it's a new issue. Could you please provide a reproduction repo for me to see it happening? You can fork our Remix example and start from there. Feel free to update the MSW/Remix versions to suit your scenario. Would be happy to look into it then. Thanks.