Skip to content

Feat/integrate msw#2

Open
coolsoftwaretyler wants to merge 6 commits into
mainfrom
feat/integrate-msw
Open

Feat/integrate msw#2
coolsoftwaretyler wants to merge 6 commits into
mainfrom
feat/integrate-msw

Conversation

@coolsoftwaretyler

@coolsoftwaretyler coolsoftwaretyler commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Example PR integrating MSW with an Ignite app on Expo 57 - exploring some of the problems you may encounter while following the MSW React Native docs.

Updated polyfill file

This updates msw.polyfills.js to include additional polyfills from this GitHub issue, which solve the following problems:

  • MSW's FetchInterceptor calls globalThis.fetch = interceptedFetch, but Hermes does not allow this assignment, so we need to delete globalThis.fetch and allow for assignment.
  • MSW references BroadcastChannel, EventTarget, Event, and MessageEvent, none of which exist in hermes.

Do not register root component after a delay

I didn't know this, but calling registerRootComponent after any kind of delay seems to break it and give you "App entry not found" errors.

This only happens if you actually await anything. You can technically call registerRootComponent in the then of a promise and it'll work, but if you've awaited anything before, it seems to fail. I can't find any specific documentation for why, but here's a video of what happens in a sample promise that just waits for a timeout:

CleanShot.2026-07-07.at.20.16.43.mp4

Tell axios to use the fetch adapter

MSW is overriding fetch, so we have to direct axios to use its fetch adapater in order for MSW to take effect at all

Patch MSW to look for request ._bodyInit before .body

When MSW intercepts a response, it creates a new FetchResponse instance, which extends the Response class. In our environment (even with expo/fetch set as the default fetch implementation, the Response class is coming from whatwg-fetch. See in the debugger:

CleanShot.2026-07-07.at.21.12.12.mp4

Also see that expo/fetch does get called if we just fetch from the console, so it seems they've polyfilled global fetch, but not Response:

CleanShot.2026-07-07.at.21.29.47.mp4

Expo also has a draft PR to implement their own Response class, which says:

expo/fetch relied on React Native's whatwg-fetch polyfill for the global Request

Unfortunately, the whatwg-fetch Response class does not implement a body getter, which means we get undefined, instead of the actual body.

Our patch reaches into _bodyInit, which contains what we want in these Response instances

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.

1 participant