Skip to content

Commit 3888713

Browse files
authored
createFromFetch -> createFromReadableStream (#72418)
The only difference between createFromFetch and createFromReadableStream is that createFromFetch accepts a promise for a fetch, and createFromReadableStream accepts a Flight ReadableStream (e.g. response.body). Since we're doing other stuff with the response object anyway there's not much point using the slightly higher-level form.
1 parent bb00a09 commit 3888713

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/next/src/client/components/router-reducer/fetch-server-response.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// @ts-ignore
44
// eslint-disable-next-line import/no-extraneous-dependencies
5-
// import { createFromFetch } from 'react-server-dom-webpack/client'
6-
const { createFromFetch } = (
5+
// import { createFromReadableStream } from 'react-server-dom-webpack/client'
6+
const { createFromReadableStream } = (
77
!!process.env.NEXT_RUNTIME
88
? // eslint-disable-next-line import/no-extraneous-dependencies
99
require('react-server-dom-webpack/client.edge')
@@ -195,7 +195,7 @@ export async function fetchServerResponse(
195195

196196
// If fetch returns something different than flight response handle it like a mpa navigation
197197
// If the fetch was not 200, we also handle it like a mpa navigation
198-
if (!isFlightResponse || !res.ok) {
198+
if (!isFlightResponse || !res.ok || !res.body) {
199199
// in case the original URL came with a hash, preserve it before redirecting to the new URL
200200
if (url.hash) {
201201
responseUrl.hash = url.hash
@@ -213,8 +213,8 @@ export async function fetchServerResponse(
213213
}
214214

215215
// Handle the `fetch` readable stream that can be unwrapped by `React.use`.
216-
const response: NavigationFlightResponse = await createFromFetch(
217-
Promise.resolve(res),
216+
const response: NavigationFlightResponse = await createFromReadableStream(
217+
res.body,
218218
{ callServer, findSourceMapURL }
219219
)
220220

0 commit comments

Comments
 (0)