-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Properly handle empty body response codes in single fetch requests #12760
Conversation
🦋 Changeset detectedLatest commit: 754f590 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
You might have forgotten to apply the fix here as well, no?
I left that out on purpose, but incorrectly it seems. I thought document requests would always need an HTML body - and in the 304 case it would use the cached body. I missed that the browser will behave the same on 204 responses and use the current document:
205 behaves the same - although interestingly enough it doesn't reset any form fields. I don't think 1xx makes sense for document requests? I'm going to leave those out and only apply them to data requests (even there I don't have a great use case for them...) |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
// some status codes are not permitted to have bodies, so we want to just | ||
// treat those as "no data" instead of throwing an exception. | ||
// 304 is not included here because the browser should fill those responses | ||
// with the cached body content. | ||
const NO_BODY_STATUS_CODES = new Set([100, 101, 204, 205]); | ||
if (NO_BODY_STATUS_CODES.has(res.status)) { | ||
if (!init.method || init.method === "GET") { | ||
// SingleFetchResults can just have no routeId keys which will result | ||
// in no data for all routes | ||
return { status: res.status, data: {} }; | ||
} else { | ||
// SingleFetchResult is for a singular route and can specify no data | ||
return { status: res.status, data: { data: undefined } }; | ||
} | ||
} |
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.
Edit: NVM, I misunderstood the spec. This is great.
Closes remix-run/remix#10328