fix: hydration for null body http status response #13985
+11
−3
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.
Fix for issue: 13972
Root cause:
The hydration logic in
[initial_fetch](https://github.com/sveltejs/kit/blob/main/packages/kit/src/runtime/client/fetcher.js#L88C17-L88C30)
constructing a Response using empty string as the response body, which is invalid for null body status codes (101, 103, 204, 205, 304) as per Fetch specs. This lead to the error:TypeError: Failed to construct 'Response': Response with null body status cannot have body
This PR basically updates the
[text()](https://github.com/sveltejs/kit/blob/main/packages/kit/src/runtime/server/page/load_data.js#L325)
function:When the response status is null body status, and the .text() result is empty string, we now:
undefined
instead of an empty stringPlease don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits