-
Notifications
You must be signed in to change notification settings - Fork 23
feat(network-activity-plugin): show http network requests on boot #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(network-activity-plugin): show http network requests on boot #143
Conversation
|
@dprevost-LMI is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
|
Unfortunately, it's not going to work in some cases. There is a slight delay between the client becoming available and the other side being ready to accept messages. In other words, useRozeniteDevToolsClient may return a client instance and allow you to send messages, but the other side may not be listening yet. I need to refactor the bridge to include some sort of handshake mechanism so both sides can confirm that they’re ready to handle communication correctly. |
I performed a few iterations and flushed the queue when I received the |
|
I have reached a point where this solution, although not entirely finalized, is the one I suggest. |
539c61d to
f67dea9
Compare
packages/network-activity-plugin/src/react-native/useNetworkActivityDevTools.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
Bug: HTTP Inspector Fails to Auto-Enable Recording
The HTTP network inspector is never automatically enabled when the component mounts, even though isRecording defaults to true in the store. The removed code that checked isRecordingEnabledRef.current and called networkInspector.enable() was necessary to enable the inspector on initial mount and after hot reloads. WebSocket and SSE inspectors still have this logic (lines 121-123 and 159-161), creating an inconsistency where HTTP requests won't be captured until the user manually toggles recording, while WebSocket and SSE connections will be captured automatically.
packages/network-activity-plugin/src/react-native/useNetworkActivityDevTools.ts#L78-L89
rozenite/packages/network-activity-plugin/src/react-native/useNetworkActivityDevTools.ts
Lines 78 to 89 in 5dfcf37
| useEffect(() => { | |
| if (!client || !isHttpInspectorEnabled) { | |
| return; | |
| } | |
| const networkInspector = getNetworkInspector(client); | |
| return () => { | |
| networkInspector.dispose(); | |
| }; | |
| }, [client, isHttpInspectorEnabled]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
packages/network-activity-plugin/src/react-native/http/network-inspector.ts
Outdated
Show resolved
Hide resolved
0ba0550 to
319ce0c
Compare
V3RON
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request includes not only recording network traffic on boot, but also changing the way how 'long requests' are displayed (status with progress). Please clean it up, so only a single feature remains.
For the implementation, instead of combining traffic inspection and queueing logic, I suggest the following approach:
a) refactor inspectors to share the same API (emit events)
b) provide a special type of an inspector accumulating events and flushing them on demand
c) detect the presence of 'queued inspector' and flush events when plugin client is ready (in practice, when DevTools UI sends some kind of 'hello' message)
type Inspector<TEventMap> = {
enable: () => void;
disable: () => void;
on<TEventType extends keyof TEventMap(type: TEventType, callback: (event: TEventMap[TEventType]) => void);
on(type: '*', callback: (event: TEventMap[keyof TEventMap]) => void);
};
type NetworkInspector = Inspector<NetworkEventMap>;
type QueuedInspector = Inspector & {
flush: () => void;
};
const networkInspector = createRozeniteNetworkInspector({
recordOnBoot: true,
});
const websocketInspector = createRozeniteWebSocketInespector();
const useNetworkActivityDevTools = ({ inspectors }) => {
const pluginClient = useRozeniteDevToolsClient({ pluginId: '...' });
useEffect(() => {
inspectors.forEach((inspector) => {
inspector.on('*', (event) => pluginClient.send(event.type, event));
if ('flush' in inspector) {
inspector.flush();
}
});
}, [inspectors, pluginClient]);
}
const App = () => {
useNetworkActivityDevTools({
inspectors: [networkInspector, websocketInspector]
});
}Note: this is pseudo-code, not production-ready 😄
In this approach, the inspector only handles inspection and passing data to the listeners. Queuing is not its concern.
|
I'll proceed to the change as you requested! Just so you know: One thing I was thinking about with this queued client is that if we can make it generic enough, it could be exposed as a generic interface, allowing any package to use it directly and be boot-time compliant. |
020a939 to
c3a31e1
Compare
a) I think I had partially done it with I might reach out to you tomorrow on Discord since it seems blurry in my mind right now! |
c3a31e1 to
e6e00f6
Compare
|
@V3RON, seeing that rn 83 will provide a network panel by default (see change logs and screenshots), then I'm not sure that iterating on this solution is a good use of time. So, what I see:
What do you think?
After discussion, even though they provide a network, but probably not WebSockets or SSE, then it is worth continuing. |
e6e00f6 to
685f480
Compare
685f480 to
490734b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was mainly renamed to http since the network is broader than HTTP and includes SSE and WS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new and different from the one before. Now the network inspector manage all 3 types, not just http
| isEnabled: () => SSEInterceptor.isInterceptorEnabled(), | ||
| dispose: () => { | ||
| SSEInterceptor.disableInterception(); | ||
| eventEmitter.events = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove since when toggling the boolean from true => false => true, refresh was required instead of hot reload only
|
@V3RON the PR should be ready now:
|
1. Still not fully align with changes request 2. Now include also sse and ws not just http 3. All inspectors are more aligned now and the network one was rename to http 4. Instead of a queue client, we use an event listener that queues and then switch to sending with tje client when available and "connect" in the hook 5. Still draft but tested and working 6. Unfinished: try to use the type suggested, review the solution if we can align it more with the changes requested
1. Use shared inspectorConfig between hook and the boot config 2. Have event-listener disabled by default and enable when withOnBootNetworkActivityRecording is called 3. Simplify the setup code phase
1. Use `withOnBootNetworkActivityRecording` in App.tsx since it is imported in main.tsx 2. Streamline the setup of all inspectors and keep only `setupXXInspector` function
…spector 1. align the http events as we had with sse & ws 2. Have all 3 http,ws and sse under the network-inspector unbrella 3. Move some http logic from network inspector to http inspector 4. Fix issue where toggling http or sse ot ws from true false true was not showing anymore in DevTools
…rted Ensure commit f78d4b4 is in there!
a007533 to
b1fffc1
Compare

Description
Using a queuing mechanism, we can queue boot clients' messages destined to the DevTool and display them once the inspector panel is connected and is ready.
TODO
withOnBootNetworkActivityRecordingRelated Issue
See #82
Context
We heavily rely on the WebSocket and HTTP requests on boot for our enterprise app, so we totally need this feature, so I took a go for it.
Testing
Tested as below, plus using unit test coverage yet to open in another PR, see preview in this PR
Screen.Recording.2025-11-15.at.6.54.19.PM.mov
Note
Adds boot-time HTTP request capture via a queued client and
withOnBootNetworkActivityRecording, includes progress/timeout support and UI updates, plus docs and playground examples.withOnBootNetworkActivityRecordingand queued client (queued-client-wrapper) to buffer events before DevTools connects;network-inspectorupdated to flush queue on enable.request-tracker(tracking, overrides, response body helpers).request-progress(with loaded/total), handletimeout; wire through store (model,derived,store) and client (shared/client).RequestListshows in-progress percent;Toolbarswaps record/stop icon logic and adds tooltip; default recording enabled.apps/.../utils/network-activity/api.ts; add "Large File" download flow usingapi.getLargeFileand UI tab;main.tsxenables on-boot recording and triggers sample requests..prettierignoreto**/distand**/coverage.Written by Cursor Bugbot for commit 020a939. This will update automatically on new commits. Configure here.