Add test case for returning responses without body (like HTTP204) #12524
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.
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:
react-router/packages/react-router/lib/server-runtime/server.ts
Line 311 in 5d96537
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:
react-router/packages/react-router/lib/dom/ssr/single-fetch.tsx
Line 429 in 5d96537
Calling
decodeViaTurboStream
fails because there's no value to decode.I believe this needs to properly handle the case where
response.body
is null and whenresponse.body
is an empty stream: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.