Repository navigation
feat(cloudflare): Add isStreamingResponse option and detect streamed RSC responses - #24932
Conversation
size-limit report 📦
|
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 4356442. Configure here.
isaacs
left a comment
There was a problem hiding this comment.
The coercion of all buffered responses to streaming feels a bit risky without an escape hatch to work around it, since workerd responses don't have a corollary to Deno's info.completed.
I think this is a good compromise, but would recommend adding the explicit hook option for users that find they need to disable this in some cases.
… RSC responses Streamed SSR (`text/html`) and RSC (`text/x-component`) responses were classified as non-streaming, so the root span ended when the handler returned and spans that ended while the body streamed were lost. Both content types are now treated as streaming when the response has no Content-Length, the same rule that `text/plain` already uses. The SDK now creates the streamed response with the original response as the init. This keeps `encodeBody: 'manual'`, so workerd no longer compresses an already compressed body a second time. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TML and RSC responses Without the `transformstream_enable_standard_constructor` compatibility flag (compatibility dates before 2022-11-30, which Hydrogen's mini-oxygen uses), workerd ignores the transformer, so `flush` and `cancel` never ran and the span was never sent. Such Workers now end the span at handler return, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…TML and RSC responses
…TML and RSC responses
4356442 to
ee216da
Compare
…TML and RSC responses
isaacs
left a comment
There was a problem hiding this comment.
Some nits and suggestions that can definitely be follow-ups.
Also: text/x-script (React Router 7 / Remix single fetch turbo-stream) is not detected, and Bun and Deno get the RSC change but no hook. The hook covers Cloudflare users for now, which is good, but incomplete.
We should track a follow-up to add the same option to Bun and Deno, so the shared heuristic has the same per-runtime override everywhere.
…TML and RSC responses
isStreamingResponse option and detect streamed RSC responses
|
Added a follow up in #25537 |
closes #22876
closes JS-3236
Description
This adds an
isStreamingResponseoption, so users can keep thehttp.serverspan open until a streamed response has been sent, for example for streamed SSR pages. Spans created while the body streams then stay inside the request.text/x-component(RSC) responses without aContent-Lengthheader now count as streamed by default. The classifier is shared, so this also applies to Bun and Deno.encodeBody: 'manual'are no longer compressed a second time.TransformStreamtransformer, so the SDK ends the span at handler return there.Detection decisions
HTML is not streamed by default, because a buffered
new Response(html)has noContent-Lengthheader either and would also go through theTransformStream. The alternative is to treat HTML without aContent-Lengthas streamed, which fixes streamed SSR without configuration.