Skip to content

Feat/integrate msw with updates - #3

Open
coolsoftwaretyler wants to merge 7 commits into
mainfrom
feat/integrate-msw-with-updates
Open

Feat/integrate msw with updates#3
coolsoftwaretyler wants to merge 7 commits into
mainfrom
feat/integrate-msw-with-updates

Conversation

@coolsoftwaretyler

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:

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

So instead of awaiting the imports, we use require to block MSW imports and register the root component after the requires resolve.

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