@@ -6,6 +6,7 @@ import { with_request_store, merge_tracing } from '@sveltejs/kit/internal/server
66import { record_span } from '../../telemetry/record_span.js' ;
77import { clarify_devalue_error , get_node_type } from '../utils.js' ;
88import { base64_encode , text_decoder } from '../../utils.js' ;
9+ import { NULL_BODY_STATUS } from '../constants.js' ;
910
1011/**
1112 * Calls the user's server `load` function.
@@ -345,7 +346,7 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
345346 const proxy = new Proxy ( response , {
346347 get ( response , key , _receiver ) {
347348 /**
348- * @param {string } body
349+ * @param {string | undefined } body
349350 * @param {boolean } is_b64
350351 */
351352 async function push_fetched ( body , is_b64 ) {
@@ -427,6 +428,11 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
427428 async function text ( ) {
428429 const body = await response . text ( ) ;
429430
431+ if ( body === '' && NULL_BODY_STATUS . includes ( response . status ) ) {
432+ await push_fetched ( undefined , false ) ;
433+ return undefined ;
434+ }
435+
430436 if ( ! body || typeof body === 'string' ) {
431437 await push_fetched ( body , false ) ;
432438 }
@@ -444,7 +450,8 @@ export function create_universal_fetch(event, state, fetched, csr, resolve_opts)
444450
445451 if ( key === 'json' ) {
446452 return async ( ) => {
447- return JSON . parse ( await text ( ) ) ;
453+ const body = await text ( ) ;
454+ return body ? JSON . parse ( body ) : undefined ;
448455 } ;
449456 }
450457
0 commit comments