fix: send responseReceived with EventSource type for SSE requests#63
Conversation
BAIXIONGSODA
left a comment
There was a problem hiding this comment.
The original mainProcess.sendRequest('updateRequest', requestDetail) only syncs the request data to the fork process cache (requests[request.id] = request) — it doesn't send any CDP message to DevTools, so it had no visible effect at that point in the SSE flow.
The new eventSourceResponseReceived handler already does the same cache update internally (line 203: requests[request.id] = request), and additionally sends Network.responseReceived with type: 'EventSource' to DevTools — which is exactly what's needed for DevTools to correctly identify and display the SSE connection.
So the two calls are not equivalent: the original updateRequest was effectively a no-op here (the cache gets properly updated again in the finally block via endRequest), while eventSourceResponseReceived replaces it with the meaningful behavior. Adding updateRequest back would just be a redundant double cache write with no additional benefit.
As for the original fetch behavior — this change is scoped entirely within handleEventStreamResponse, which is only entered when the response Content-Type is text/event-stream. All regular (non-SSE) fetch requests go through the existing fetchResponseHandlerFactory path, which is completely untouched.
|
It's nice that you're willing to keep optimizing. |
|
I added you to [Collaborators], after which you can submit directly on the repository~ |
I'm glad I could help. I've accepted the invitation. |
PR: Fix SSE (Server-Sent Events) DevTools Display
Summary
This PR fixes the SSE request display in Chrome DevTools Network panel by sending
Network.responseReceivedwithtype: EventSourcebefore streaming SSE messages.Changes
packages/network-debugger/src/core/fetch.tsloadCallFrames()call to capture initiator stack trace for fetch requestseventSourceResponseReceivedmessage to properly notify DevTools about SSE responsespackages/network-debugger/src/fork/module/network/index.tseventSourceResponseReceivedto sendNetwork.responseReceivedwithtype: EventSourceWhy
Previously, SSE requests were not properly displayed in DevTools because the
responseReceivedevent was not sent with the correcttype: EventSource. This fix ensures:EventSourceTesting
Tested with
koa-esmapp's/sse-fetchendpoint - SSE events are now properly captured and displayed in DevTools.