Skip to content

[NetworkReporter] Fix decodedBodyLength always 0 for images in trace events - #60245

Open
robhogan wants to merge 1 commit into
react:mainfrom
robhogan:rn-image-decoded-size
Open

robhogan wants to merge 1 commit into
react:mainfrom
robhogan:rn-image-decoded-size

Conversation

@robhogan

@robhogan robhogan commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary:

NetworkReporter::reportResponseEnd erases the request's timing entry, then looks it up again to get decodedBodySize for image/* responses. That lookup always misses, so the Performance panel shows "0 B" decoded size for every image fetch/XHR:

perfTimingsBuffer_.erase(requestId);
}
}
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
// Debugger enabled: CDP event handling
jsinspector_modern::NetworkHandler::getInstance().onLoadingFinished(
requestId, encodedDataLength);
// Debugger enabled: Add trace event to Performance timeline
{
int decodedBodyLength = 0;
std::lock_guard<std::mutex> lock(perfTimingsMutex_);
auto it = perfTimingsBuffer_.find(requestId);
if (it != perfTimingsBuffer_.end() &&
it->second.contentType.starts_with("image/")) {
decodedBodyLength = it->second.decodedBodySize;
}

This has never worked with enableResourceTimingAPI on, which is the default from 0.83: #53840 added the lookup after that flag's erase. This reads the value before the erase, clamped to 0 because it's -1 when the content length is unknown.

Changelog:

[General][Fixed] - React Native DevTools: Fix decoded body size always showing 0 for image network requests in the Performance panel

Test Plan:

New C++ test, which fails on main with decodedBodyLength: 0. Also checked the non-debugger build compiles under -Werror.

Screenshots of the "Decoded body" row for a fetch of a PNG in RNTester on Android:

Before

before-annotated

After

after-annotated

@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 23, 2026
@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 23, 2026
@robhogan

Copy link
Copy Markdown
Collaborator Author

Spotted while reviewing #60235.

@huntie not sure whether you'd want to pick this? Looks like you're polishing network reporting in 0.89

@robhogan
robhogan requested a review from huntie November 23, 2026 19:39
…events

`NetworkReporter::reportResponseEnd` erases the request's `ResourceTimingData` after reporting `PerformanceResourceTiming`, then looks the same entry up again to pass `decodedBodySize` for `image/*` responses to `PerformanceTracer::reportResourceFinish`. The second lookup always misses, so every `ResourceFinish` trace event has `decodedBodyLength: 0`, and the DevTools Performance panel shows "0 B" decoded size for image requests reported through `NetworkReporter` (`fetch`/XHR, and third-party image libraries that report to it).

This has never worked with `enableResourceTimingAPI` on, which is the default from 0.83: react#53840 added the lookup after that flag's erase. react#54511 later made the erase unconditional.

This change reads the value before the erase and drops the second lock and lookup. A response with no known content length reports -1 here, which is clamped to 0 rather than shown as "-1B".

Changelog: [General][Fixed] - **React Native DevTools**: Fix decoded body size always showing 0 for image network requests in the Performance panel
@robhogan
robhogan force-pushed the rn-image-decoded-size branch from 53f57de to 7cfcef5 Compare November 23, 2026 19:58
@huntie

huntie commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Awesome, let's do that, definitely a small bug fix! @huntie-bot action on merge.

This branch has not been deployed

No deployments
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.

2 participants