From 3d78f07f2f3c6ae4c4fd5d2a230cb80b5123a7d1 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 17 Dec 2025 13:55:41 -0800 Subject: [PATCH] Gate requestBody processing behind BuildConfig.DEBUG (#54920) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54920 Gates `requestBody` handling for `reportRequestStart` on Android with `BuildConfig.DEBUG`. This is an appropriate optimisation as we do not use body previews outside of CDP debugging, aligning with the same conditional behaviour on iOS. I'd like to also pick this change for 0.83.1, with D89373824, for additional safety. **Other notes** Gating by `BuildConfig` isn't done elsewhere in this file, as other potentially expensive behaviour is gated lower down by both `REACT_NATIVE_DEBUGGER_ENABLED` and the `Network.enable` CDP message. This was the only remaining gap with the iOS implementation. Changelog: [Internal] Reviewed By: vzaidman Differential Revision: D89377163 fbshipit-source-id: 10a27f6b02f65755d4293f5cf33697d542bc9465 --- .../react/modules/network/NetworkEventUtil.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt index c0ed0c96584..2b4dee4bbb3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt @@ -15,6 +15,7 @@ import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.WritableMap import com.facebook.react.bridge.buildReadableArray +import com.facebook.react.common.build.ReactBuildConfig import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags import java.net.SocketTimeoutException import okhttp3.Headers @@ -30,13 +31,21 @@ internal object NetworkEventUtil { fun onCreateRequest(devToolsRequestId: String, request: Request) { if (ReactNativeFeatureFlags.enableNetworkEventReporting()) { val headersMap = okHttpHeadersToMap(request.headers()) + var requestBody = "" + + if (ReactBuildConfig.DEBUG) { + // Debug build: Process request body for preview (CDP only) + requestBody = + (request.body() as? ProgressRequestBody)?.getBodyPreview() + ?: request.body()?.toString().orEmpty() + } + InspectorNetworkReporter.reportRequestStart( devToolsRequestId, request.url().toString(), request.method(), headersMap, - (request.body() as? ProgressRequestBody)?.getBodyPreview() - ?: request.body()?.toString().orEmpty(), + requestBody, request.body()?.contentLength() ?: 0, ) InspectorNetworkReporter.reportConnectionTiming(devToolsRequestId, headersMap)