You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 61a0ff1
Browse filesBrowse the repository at this point in the historyBrowse files
**Why this is needed:** MSW assumes a browser-like environment. On Hermes, `globalThis.fetch` is non-writable and `BroadcastChannel`, `EventTarget`, `Event`, `MessageEvent`, and `XMLHttpRequestUpload` are all missing, causing MSW to crash at runtime. See the [MSW #2367 discussion](https://github.com/mswjs/msw/issues/2367#issuecomment-4311536712) for background.
35
+
**Why this is needed:** MSW assumes a browser-like environment. On Hermes, `BroadcastChannel`, `EventTarget`, `Event`, `MessageEvent`, and `XMLHttpRequestUpload` are all missing, causing MSW to crash at runtime. See the [MSW #2367 discussion](https://github.com/mswjs/msw/issues/2367#issuecomment-4311536712) for background.
36
36
37
-
The polyfill file below handles six things:
37
+
The polyfill file below handles these things:
38
38
39
-
1. Imports `fast-text-encoding` and `react-native-url-polyfill` for `TextEncoder`/`URL` support
40
-
2. Deletes and re-defines `globalThis.fetch` as writable so MSW can replace it
41
-
3. Stubs `Event` with enough of the interface for MSW's internal event dispatching
42
-
4. Stubs `EventTarget` with `addEventListener`/`removeEventListener`/`dispatchEvent`
43
-
5. Stubs `MessageEvent`, `XMLHttpRequestUpload`, and `BroadcastChannel`
44
-
6. Wraps `XMLHttpRequest.getAllResponseHeaders()` to never return `null` (Hermes quirk that causes MSW to crash on `.split()`)
39
+
1. Imports `fast-text-encoding`, `react-native-url-polyfill` and `web-streams-polyfill` to handle missing polyfills
40
+
2. Stubs `MessageEvent`, and `BroadcastChannel`
45
41
46
42
```js title="msw.polyfills.js"
47
43
import"fast-text-encoding"
48
44
import"react-native-url-polyfill/auto"
49
-
50
-
// Issue 1: globalThis.fetch is non-writable in Hermes.
51
-
// MSW's FetchInterceptor does `globalThis.fetch = interceptedFetch`, but Hermes
52
-
// exposes fetch as a non-configurable native binding. The assignment silently
53
-
// fails — no error thrown, MSW reports it's listening, but no requests are
54
-
// intercepted. We must delete and re-define the property as writable/configurable
0 commit comments