Skip to content

Commit 1bf7d4d

Browse files
authored
Use createFromFetch instead of createFromReadableStream to fetch Flight (#40656)
Small change leveraging the `createFromFetch` method instead. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent 34df81e commit 1bf7d4d

File tree

1 file changed

+5
-22
lines changed

1 file changed

+5
-22
lines changed

packages/next/client/components/app-router.client.tsx

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

33
import type { PropsWithChildren, ReactElement, ReactNode } from 'react'
44
import React, { useEffect, useMemo, useCallback } from 'react'
5-
import { createFromReadableStream } from 'next/dist/compiled/react-server-dom-webpack'
5+
import { createFromFetch } from 'next/dist/compiled/react-server-dom-webpack'
66
import {
77
AppRouterContext,
88
LayoutRouterContext,
@@ -32,11 +32,11 @@ import { useReducerWithReduxDevtools } from './use-reducer-with-devtools'
3232
/**
3333
* Fetch the flight data for the provided url. Takes in the current router state to decide what to render server-side.
3434
*/
35-
function fetchFlight(
35+
export function fetchServerResponse(
3636
url: URL,
3737
flightRouterState: FlightRouterState,
3838
prefetch?: true
39-
): ReadableStream {
39+
): Promise<FlightData> {
4040
const flightUrl = new URL(url)
4141
const searchParams = flightUrl.searchParams
4242
// Enable flight response
@@ -50,26 +50,9 @@ function fetchFlight(
5050
searchParams.append('__flight_prefetch__', '1')
5151
}
5252

53-
// TODO-APP: Verify that TransformStream is supported.
54-
const { readable, writable } = new TransformStream()
55-
56-
fetch(flightUrl.toString()).then((res) => {
57-
res.body?.pipeTo(writable)
58-
})
59-
60-
return readable
61-
}
62-
63-
/**
64-
* Fetch the flight data for the provided url. Takes in the current router state to decide what to render server-side.
65-
*/
66-
export function fetchServerResponse(
67-
url: URL,
68-
flightRouterState: FlightRouterState,
69-
prefetch?: true
70-
): Promise<FlightData> {
53+
const promise = fetch(flightUrl.toString())
7154
// Handle the `fetch` readable stream that can be unwrapped by `React.use`.
72-
return createFromReadableStream(fetchFlight(url, flightRouterState, prefetch))
55+
return createFromFetch(promise)
7356
}
7457

7558
/**

0 commit comments

Comments
 (0)