Skip to content

Fix WebSocket request initiator for framework call sites - #59682

Open
huntie wants to merge 1 commit into
mainfrom
pr59682
Open

huntie wants to merge 1 commit into
mainfrom
pr59682

Conversation

@huntie

@huntie huntie commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Addresses a small correctness/usability bug with WebSocket events in React Native DevTools.

The bug

Previously, the reported call stack for Network.webSocketCreated CDP events starts at the WebSocket constructor's own frame. DevTools hides that frame while any non-ignore-listed frame exists (i.e. in product code), but for sockets opened entirely from framework code, such as Metro's /hot Fast Refresh connection, every frame is ignore-listed and the Initiator column falls back to the top frame, showing WebSocket.js:147.

Fix

__NETWORK_REPORTER__.createDevToolsRequestId now takes an optional framesToSkip count, dropped from the serialized CDP call frames, and WebSocket passes 1 for its constructor. The top frame is then the caller of new WebSocket(), matching Chrome's initiator semantics for a native API, so /hot resolves to metro-runtime's HMRClient.

Before After
⚠️ Internal call site (1) resolves to WebSocket.js, which isn't particularly useful (internals of the WebSocket API itself) ✅ Internal call site resolves to HMRClient.js (Metro hot reload client, more useful) ✅ Product call site unchanged

Notes

  • The skip is applied to the serialized frames rather than through RuntimeTargetDelegate::captureStackTrace(framesToSkip), which the console path already uses to mean the host-function frame that Hermes strips itself.

This is the last known bug I had tracked before enabling WS support everywhere in #59683.

Changelog:
[General][Fixed] - React Native DevTools: Fix the initiator of WebSocket connections opened from framework code, such as Metro's Fast Refresh socket, in the Network panel

Test Plan

  • yarn flow-check, ESLint and Prettier on the changed files.
  • Added testWebSocketCreatedWithInitiatorFramesToSkip. ⚠️ Not run locally: jsinspector-modern tests have no OSS build.
  • RNTester on an iOS 27.2 simulator with fuseboxWebSocketEventsEnabled, React Native DevTools Network panel, Initiator column. Product-code sockets were opened from a local RNTester example covering four call-site shapes:
Socket Before After
Metro /hot WebSocket.js:147 HMRClient.js:24
new WebSocket() in a press handler WebSocketExample.js:167 unchanged
Via a helper function WebSocketExample.js:130 unchanged
Inside setTimeout WebSocketExample.js:180 unchanged
From a WebSocket subclass constructor WebSocketExample.js:133 unchanged

@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 Oct 30, 2026
@huntie
huntie added this pull request to stack #59684 October 30, 2026 17:00
@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 Oct 30, 2026
@huntie huntie changed the title Fix WebSocket request initiators for sockets opened from framework code Fix WebSocket request initiator for framework call sites Oct 30, 2026

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

1 participant