-
Notifications
You must be signed in to change notification settings - Fork 82
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
Modify parsing of response for Connect unary requests #668
Conversation
@timostamm I saw some tests for Connect and JSON format already present in the |
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.
Now that we support a feature that relies on the specific behavior of calling Response#json, we need to add a test to make sure we do not regress. Can you add test that provides a mocked fetch
to the transport?
Sure. Do you want the mocked |
The |
Co-authored-by: Timo Stamm <ts@timostamm.de>
@timostamm lmk what you think of this approach. I went with Jasmine spies because it seemed a lot easier to reason about. It's a bit tough to use the spies for the |
There is a simple solution for this problem: Don't use describeTransports. Pushed up 6369528 as an example. You can also avoid using a server completely. Pushed up c236657 as an example. This one also covers error responses. Errors are always JSON, even when the request was made with the binary format. This is easily missed, so we should cover it. Please use the examples as you see fit, but:
|
Much simpler, thank you. Updated the PR. |
This modifies the response parsing for Connect unary requests based on the serialization format. If
useBinaryFormat
is true, it will use the output type'sfromBinary
againstresponse.arrayBuffer
.If the serialization format is JSON, it will use the output type's
fromJson
method againstresponse.json
.Note that this fixes two outstanding issues:
It allows React-Native to be used with Connect unary requests without the need for patches. See Add custom transport for React-Native examples-es#602 for more information. With this change in place, the React-Native example in Connect-ES Integration works over Connect and unary. Note that streaming still is out of scope.
This also fixes the hidden issues with Svelte and universal SSR. Tests were run with the Svelte example in Connect-ES Integration using this change and universal SSR is working as intended:
No additional XHR requests issued from the browser
Hydration data in the document returned from the initial
load
call: