Skip to content

Fix (android): show payload preview for FormData and one-shot uploads in DevTools (#55764)#56742

Open
HarshitMadhav wants to merge 2 commits intofacebook:mainfrom
HarshitMadhav:fix/55764-android-payload-preview
Open

Fix (android): show payload preview for FormData and one-shot uploads in DevTools (#55764)#56742
HarshitMadhav wants to merge 2 commits intofacebook:mainfrom
HarshitMadhav:fix/55764-android-payload-preview

Conversation

@HarshitMadhav
Copy link
Copy Markdown

Summary:

Follow-up to #56406. After that PR landed, NetworkEventUtil.getRequestBodyPreview still returns the literal string "[Preview unavailable]" in two cases:

The top-level RequestBody.isOneShot() is true (e.g. a single URI/file upload).
The body is a MultipartBody whose parts include any one-shot stream (the common case for FormData with files on Android).
Both branches exist for a good reason — calling writeTo() on a one-shot stream would drain it and break the real upload. This PR keeps that invariant but replaces the two return sites with structured previews:

Single one-shot body → [Binary data, N bytes] (or [Binary data] if contentLength() is unknown).
MultipartBody with one-shot parts → a multipart envelope using the request's actual boundary, with text parts inlined and one-shot parts replaced by [Binary data, N bytes]. The result parses cleanly against the on-the-wire Content-Type: multipart/form-data; boundary=..., so DevTools renders it the same way it renders any other multipart payload.
Net result: issue #55764 (no payload preview for FormData / file uploads in the React Native DevTools Network tab) is closed, with no change to what gets sent on the wire.

Changelog:

NetworkEventUtil.kt: replace the two "[Preview unavailable]" returns with binaryPartLabel(body) and a new previewMultipartWithBinaryParts(body) helper. No change to the existing all-text path.

NetworkEventUtilTest.kt: 6 new tests covering null body, plain string body, ProgressRequestBody unwrapping, multipart with text parts, multipart with a file part, and a single one-shot body.

[ANDROID] [FIXED] - Show request body preview for FormData and file uploads in DevTools Network tab

Test Plan:

  1. ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.modules.network.*" — 16/16 pass in NetworkEventUtilTest, full network suite green.

  2. Manual: in RN-Tester debug build, POST a FormData with a file using fetch → DevTools Network → Payload tab now shows the multipart envelope with [Binary data, N bytes] instead of [Preview unavailable].

  3. Manual: POST a single-file RequestBody from a URI → preview now shows [Binary data, N bytes].

Stream safety
The whole point of #56406's bail-outs was to avoid draining one-shot streams. This PR preserves that: it never calls writeTo() on a body whose isOneShot() is true. The only RequestBody methods invoked on one-shot bodies are contentType() and contentLength(), both of which are pure getters per the OkHttp docs.

Refs #55764, follows up on #56406.

@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 May 8, 2026
@HarshitMadhav HarshitMadhav force-pushed the fix/55764-android-payload-preview branch from 1981a55 to c099d9d Compare May 8, 2026 21:17
@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 May 8, 2026
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. 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.

1 participant