Skip to content

[NetworkReporter][iOS] Add text variant of maybeStoreResponseBody - #60188

Merged
huntie merged 1 commit into
mainfrom
pr60188
Nov 26, 2026
Merged

huntie merged 1 commit into
mainfrom
pr60188

Conversation

@huntie

@huntie huntie commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Context

Expo is moving expo/fetch, expo-image and expo-asset onto RCTInspectorNetworkReporter and InspectorNetworkReporter, in place of its own CDP relay in Expo CLI. This stack fills the gaps in those APIs for networking stacks that replace RCTNetworking and NetworkingModule.

This diff

Add a typed way to store a complete text response preview from Swift. maybeStoreResponseBody:data:base64Encoded: declares NSData, though its implementation also accepts an NSString, so Swift callers cannot reach that branch. Expo routes through a small Objective-C helper that passes the string as id (expo/expo#53160); maybeStoreResponseBodyIncremental accepts a string, but keeps a second copy in a process-wide buffer until reportResponseEnd.

  • Add maybeStoreResponseBody:body:, which stores a decoded text body, and is a no-op when CDP debugging is disabled.
  • Leave maybeStoreResponseBody:data:base64Encoded: unchanged, since RCTNetworking relies on its NSString branch for base64 strings.

Changelog:
[iOS][Added] - React Native DevTools: RCTInspectorNetworkReporter maybeStoreResponseBody:body: method, to store text response previews from Swift

Test Plan

Built Expo's bare-expo app from source against React Native 0.89.0-rc.2, whose copy of these files is identical to main, with this change applied and Expo's Swift reporter calling the new method in place of its Objective-C helper:

RCTInspectorNetworkReporter.maybeStoreResponseBody(requestId, body: text)
  • ✅ Builds, with Swift resolving maybeStoreResponseBody(_:body:).
  • ✅ On an iPhone simulator (iOS 27.2), with the Network domain enabled over CDP, an expo/fetch request for a JSON response returned its full body from Network.getResponseBody, as text (base64Encoded: false).
yarn cxx-api-build

ℹ️ Adds the method to the four ReactApple snapshots. The ReactAndroid views failed locally on an unrelated Doxygen parse error in fmt's headers.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 20, 2026
@huntie
huntie added this pull request to stack #60189 November 20, 2026 17:36
@huntie
huntie removed this pull request from stack #60189 November 20, 2026 18:17
@huntie
huntie changed the base branch from pr60187 to main November 20, 2026 18:17
@huntie
huntie force-pushed the pr60188 branch 2 times, most recently from a64a863 to 49bde6d Compare November 20, 2026 18:42
@huntie huntie changed the title Add text variant of maybeStoreResponseBody to RCTInspectorNetworkReporter [NetworkReporter][iOS] Add text variant of maybeStoreResponseBody Nov 23, 2026
@huntie
huntie changed the base branch from main to pr60239 November 24, 2026 12:56
@huntie
huntie marked this pull request as ready for review November 24, 2026 12:57
@huntie
huntie added this pull request to stack #60262 November 24, 2026 12:57
huntie added a commit to expo/expo that referenced this pull request Nov 24, 2026
…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)
@cipolleschi
cipolleschi force-pushed the pr60188 branch 2 times, most recently from daeba47 to f5fc2b4 Compare November 24, 2026 16:29

@gabrieldonadel gabrieldonadel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@huntie
huntie enabled stacked auto-merge (squash) November 26, 2026 17:29
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 26, 2026

@gabrieldonadel gabrieldonadel left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 26, 2026
@huntie
huntie merged commit 1dacaec into main Nov 26, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. p: Expo Partner: Expo Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants