@connectrpc/connect-web unlock client and bidi streaming in supported browsers #1375
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #669 (comment) this PR brings client-side streaming (client or bidi) to supported browsers in
@connectrpc/connect-web
. The behavior in Google's grpc-web appears to allow client-side streaming in supported browsers and has quirky behavior in unsupported ones (see linked comment for specifics). However, this PR aims to simplify the developer experience by immediately throwing if a client-side streaming RPC is started on an unsupported browser. I believe that this PR does not introduce any harm or backwards compatibility errors because the preexisting case was that all client-side streaming calls would throw. We only unlock the capability when possible, and effectively do not change the existing behavior for unsupported browsers.Support browsers are known to include Chromium-based browsers. Unsupported browsers are known to include Firefox and Safari.
Previous error message:
The fetch API does not support streaming request bodies
Revised to:
The fetch API does not support streaming request bodies in this browser
Note that the logic to detect compatibility is following the Chrome Developer docs which explains the nuance around how/why it works: https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#feature_detection
There's an important caveat: Only half duplex support is available. So while bidi streams do work, you will not see server responses until after the client finishes sending its stream. Once the client finishes its iterator, all prior server responses are immediately sent. From that point on, if the server's iterator is still producing more responses, those will continue to stream in as per normal.