feat(reactotron-react-native): track Expo expo/fetch in the networking plugin#1613
Open
ShanavasPS wants to merge 1 commit into
Open
feat(reactotron-react-native): track Expo expo/fetch in the networking plugin#1613ShanavasPS wants to merge 1 commit into
ShanavasPS wants to merge 1 commit into
Conversation
…g plugin
Expo SDK 54+ installs expo/fetch as the default globalThis.fetch. It is
backed by a native module and bypasses XMLHttpRequest, so XHRInterceptor
never sees it and the networking plugin silently misses all fetch traffic
on Expo.
Add a FetchInterceptor that mirrors XHRInterceptor (set*Callback /
enableInterception / disableInterception) and wraps the global fetch only
when it is the expo/fetch builtin (detected via Symbol.for("expo.builtin")).
RN's XHR-backed fetch is left to XHRInterceptor, so there is no double
reporting. The networking plugin wires Reactotron into it in onConnect,
gated by a new `ignoreExpoFetch` option.
The wrapper returns the original response immediately and reads the body
off a clone asynchronously, so callers are never blocked; image and
text/event-stream bodies are skipped so streaming responses are not
buffered.
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.
Please verify the following:
yarn build-and-test:localpassesREADME.md(or relevant documentation) has been updated with your changesDescribe your PR
Closes #1612 .
Problem
Expo SDK 56 installs
expo/fetchas the defaultglobalThis.fetch.expo/fetchis backed by a native module and bypassesXMLHttpRequest, so thenetworkingplugin'sXHRInterceptornever sees it — on Expo SDK 56+ the plugin silently misses allfetchtraffic.(For context, the existing
XHRInterceptoronly covers React Native's XHR-backedfetch. The same blind spot affects other XHR-based network inspectors on Expo SDK 56+.)Solution
Add a
FetchInterceptorthat mirrorsXHRInterceptor's shape (set*Callback/enableInterception/disableInterception) and wraps the globalfetchonly when it is theexpo/fetchbuiltin, detected viaSymbol.for("expo.builtin"). React Native's XHR-backedfetchis left toXHRInterceptor, so there is no double-reporting. Thenetworkingplugin wires Reactotron into it inonConnect, gated by a newignoreExpoFetchoption.Care was taken to keep this safe for
expo/fetch's streaming model:Responseimmediately and reads the body off a clone, asynchronously — the caller is never blocked and streaming bodies stay intact.text/event-stream(and the existing image content types) are never cloned/read, so streaming responses aren't buffered.Request/URL/string argument forms is handled in the interceptor; query-param parsing, content-type policy, and timing stay in the plugin (matching the XHR path).Files
lib/reactotron-react-native/src/fetch-interceptor.ts— new, mechanism only (mirrorsxhr-interceptor.ts)lib/reactotron-react-native/src/fetch-interceptor.test.ts— unit tests (no-op off Expo, wrap/callbacks, rejection, no double-wrap, restore on disable)lib/reactotron-react-native/src/plugins/networking.ts— wire inFetchInterceptor, addignoreExpoFetchoptiondocs/plugins/networking.md— document expo/fetch support andignoreExpoFetchNotes / known limitations
globalThis.fetchis notexpo/fetch.globalThis.fetchis wrapped. Code that doesimport { fetch } from 'expo/fetch'and captures the reference directly bypasses this (as it does the XHR interceptor); the global wrap covers the common case.onConnect, so requests fired before Reactotron connects aren't captured.