Skip to content
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

Add test case for returning responses without body (like HTTP204) #12524

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

clovis1122
Copy link

@clovis1122 clovis1122 commented Dec 11, 2024

Currently, it seems that neither RR7 or Remix (w/ SingleFetch) support returning responses without a body, such as HTTP204.

Here's a StackBlitz as well: https://stackblitz.com/edit/vitejs-vite-y28rvf4p. Go to /home and click submit.

I spotted the issue in two places: first, on the server:

This is where the test error is triggered, because the code attempts to create a response with http status 204 (which does not take a body). I think a simple check for if (!response.body) check will suffice.

Assuming the server issue is fixed, the second stumbling block would be on the client in this function:

let decoded = await decodeViaTurboStream(res.body, window);
.

Calling decodeViaTurboStream fails because there's no value to decode.

Sidenote: There's a check for res.body a few lines above, but it doesn't quite work. In my browser (Edge), this value is a ReadableStream even on http204. From what I see at MDN:

Note: Current browsers don't actually conform to the spec requirement to set the body property to null for responses with no body (for example, responses to HEAD requests, or 204 No Content responses).

I believe this needs to properly handle the case where response.body is null and when response.body is an empty stream:

  • We can clone the response body (likely expensive).
  • Modify tubo-stream to return null/undefined when the stream is empty. Handle this on RR side.
  • Modify turbo-stream to throw an error different from SyntaxError. Handle this on RR side.

The relevant code for turbo-stream is here.

FYI I'm looking forward to seeing this backported into Remix as well. Let me know how I can help.

Copy link

changeset-bot bot commented Dec 11, 2024

⚠️ No Changeset found

Latest commit: e3ae80a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant