Feat/integrate msw#2
Open
coolsoftwaretyler wants to merge 6 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jsto include additional polyfills from this GitHub issue, which solve the following problems:FetchInterceptorcallsglobalThis.fetch = interceptedFetch, but Hermes does not allow this assignment, so we need to deleteglobalThis.fetchand allow for assignment.BroadcastChannel,EventTarget,Event, andMessageEvent, none of which exist in hermes.Do not register root component after a delay
I didn't know this, but calling
registerRootComponentafter any kind of delay seems to break it and give you "App entry not found" errors.This only happens if you actually
awaitanything. You can technically callregisterRootComponentin thethenof 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
fetchadapterMSW is overriding
fetch, so we have to direct axios to use its fetch adapater in order for MSW to take effect at allPatch MSW to look for request
._bodyInitbefore.bodyWhen MSW intercepts a response, it creates a new FetchResponse instance, which extends the
Responseclass. In our environment (even withexpo/fetchset as the default fetch implementation, theResponseclass is coming fromwhatwg-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
fetchfrom the console, so it seems they've polyfilled global fetch, but notResponse:CleanShot.2026-07-07.at.21.29.47.mp4
Expo also has a draft PR to implement their own
Responseclass, which says:Unfortunately, the
whatwg-fetchResponseclass does not implement a body getter, which means we getundefined, instead of the actual body.Our patch reaches into
_bodyInit, which contains what we want in these Response instances