Repository navigation
Conversation
a64a863 to
49bde6d
Compare
…53160) ## Summary **Context - 1P Network Reporting in Expo** Expo's CDP `Network` support predates React Native's first party support in 0.83, with an Expo CLI based stack that bypasses `RCTNetworking` and the modern CDP infra in core. This stack aims to migrate Expo to the upstream `InspectorNetworkReporter` stack, gaining tighter native functionality and allowing us to drop the Expo CLI relay. **This diff** Follow-up to #52866 from review. - Make `ExpoNetworkReporter` a singleton, `ExpoNetworkReporter.shared`, as `RCTInspectorNetworkReporter` is one. Each method takes the request id, and in-flight requests live in one dictionary behind one `Mutex`, the core backport rather than `NSLock`, so a call out of order or after the request has finished never reaches `RCTInspectorNetworkReporter`. - Store text bodies through the string branch of `maybeStoreResponseBody`, by way of a small Objective-C helper since the header types the argument as `NSData`, with a TODO for the text variant in react/react-native#60188. That path writes under the core reporter's lock, unlike `maybeStoreResponseBodyIncremental`, whose process-wide buffer `RCTNetworking` appends to on its own queue without one. - Store and end a finished request outside the lock, so decoding a body up to the 1 MB preview cap never blocks other requests. - Stop buffering once a response exceeds the 1 MB preview cap, instead of appending every later chunk that fits. - Rename the lifecycle methods to match `ExpoRequestInterceptorProtocolDelegate`: `willSendRequest`, `didReceiveResponse`, `didReceiveData`, `didFinishLoading` and `didFailLoading`. `reportResponseEnd` still reads and removes from that buffer without a lock in React Native; react/react-native#60187 adds the lock upstream. Linear: [ENG-28824](https://linear.app/expo/issue/ENG-28824/integrate-rn-networkreporter-stack-into-core-expo-modules-ios) (parent ENG-27596, SDK 59) ## Test Plan Built `bare-expo` at each layer of this stack, on an iPhone simulator (iOS 27.2) and an Android emulator (API 37), against React Native 0.89.0-rc.2, rebuilding the `expo` and `expo-image` JS at each layer. With `EXPO_UNSTABLE_CORE_NETWORK_INSPECTOR=1` and the Network domain enabled over CDP, `Runtime.evaluate` drove an `expo/fetch` request, `Image.loadAsync` and `Asset.downloadAsync`: | Layer | iOS | Android | |---|---|---| | #53160 (this) | ✅ Builds; nothing reported yet | — | | #52867 | ✅ fetch: text body, initiator stack | — | | #52868 | ✅ + image: base64 body | — | | #52870 | ✅ + image initiator stack | — | | #53028 | — | ✅ Builds; nothing reported yet | | #53029 | — | ✅ fetch: text body, initiator stack | | #53030 | — | ✅ + image: base64 body, initiator stack | | #53031 | ✅ + asset, no body | ✅ + asset: base64 body | | #53720, #53721 | ✅ unchanged | ✅ unchanged | At the top of the stack on iOS: - ✅ 30 concurrent `expo/fetch` requests all finish with their text bodies. - ✅ `Image.prefetch` is reported. - ✅ With `EXPO_UNSTABLE_CORE_NETWORK_INSPECTOR` unset, fetch, image, prefetch and asset requests each show once. ## Screenshots No UI change. ## Checklist <!-- Please check the appropriate items below if they apply to your diff. --> - [ ] I added a changeset and followed [this short guide](https://github.com/expo/expo/blob/main/CONTRIBUTING.md#-before-submitting) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md)
daeba47 to
f5fc2b4
Compare
gabrieldonadel
left a comment
There was a problem hiding this comment.
Small, focused addition that closes a real Swift ergonomics gap. A typed NSString overload is the right shape: it keeps the existing NSData/id method untouched for RCTNetworking and roughly matches Android's InspectorNetworkReporter.maybeStoreResponseBody(requestId: String, body: String, ...).
One correctness issue needs fixing before this becomes the recommended text path. RCTStringViewFromNSString builds the string_view from UTF8String but sizes it with string.length. That is the UTF-16 code unit count, not the UTF-8 byte count, so any non-ASCII body gets silently truncated, possibly mid-codepoint. The existing NSData branch never hits this, because base64 is ASCII. The new method exists specifically for decoded text, where non-ASCII content is common (JSON with accents or CJK text, emoji). The test plan's JSON response was most likely ASCII-only.
Summary
Context
Expo is moving
expo/fetch,expo-imageandexpo-assetontoRCTInspectorNetworkReporterandInspectorNetworkReporter, in place of its own CDP relay in Expo CLI. This stack fills the gaps in those APIs for networking stacks that replaceRCTNetworkingandNetworkingModule.This diff
Add a typed way to store a complete text response preview from Swift.
maybeStoreResponseBody:data:base64Encoded:declaresNSData, though its implementation also accepts anNSString, so Swift callers cannot reach that branch. Expo routes through a small Objective-C helper that passes the string asid(expo/expo#53160);maybeStoreResponseBodyIncrementalaccepts a string, but keeps a second copy in a process-wide buffer untilreportResponseEnd.maybeStoreResponseBody:body:, which stores a decoded text body, and is a no-op when CDP debugging is disabled.maybeStoreResponseBody:data:base64Encoded:unchanged, sinceRCTNetworkingrelies on itsNSStringbranch for base64 strings.Changelog:
[iOS][Added] - React Native DevTools:
RCTInspectorNetworkReportermaybeStoreResponseBody:body:method, to store text response previews from SwiftTest Plan
Built Expo's
bare-expoapp from source against React Native 0.89.0-rc.2, whose copy of these files is identical tomain, with this change applied and Expo's Swift reporter calling the new method in place of its Objective-C helper:maybeStoreResponseBody(_:body:).expo/fetchrequest for a JSON response returned its full body fromNetwork.getResponseBody, as text (base64Encoded: false).ℹ️ Adds the method to the four
ReactApplesnapshots. TheReactAndroidviews failed locally on an unrelated Doxygen parse error infmt's headers.