Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-web-streams: remove tee shim, use ReadableStream.tee #54079

Merged
merged 12 commits into from
Aug 17, 2023
3 changes: 1 addition & 2 deletions packages/next/src/server/app-render/use-flight-response.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight-manifest-plugin'
import type { FlightResponseRef } from './flight-response-ref'
import { readableStreamTee } from '../stream-utils/node-web-streams-helper'
import { encodeText, decodeText } from '../stream-utils/encode-decode'
import { htmlEscapeJsonString } from '../htmlescape'

Expand All @@ -26,7 +25,7 @@ export function useFlightResponse(
createFromReadableStream,
} = require(`react-server-dom-webpack/client.edge`)

const [renderStream, forwardStream] = readableStreamTee(req)
const [renderStream, forwardStream] = req.tee()
const res = createFromReadableStream(renderStream, {
moduleMap: isEdgeRuntime
? clientReferenceManifest.edgeSSRModuleMapping
Expand Down
23 changes: 0 additions & 23 deletions packages/next/src/server/stream-utils/node-web-streams-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@ export function cloneTransformStream(source: TransformStream) {
return clone
}

export function readableStreamTee<T = any>(
readable: ReadableStream<T>
): [ReadableStream<T>, ReadableStream<T>] {
const transformStream = new TransformStream()
const transformStream2 = new TransformStream()
const writer = transformStream.writable.getWriter()
const writer2 = transformStream2.writable.getWriter()

const reader = readable.getReader()
async function read() {
const { done, value } = await reader.read()
if (done) {
await Promise.all([writer.close(), writer2.close()])
return
}
await Promise.all([writer.write(value), writer2.write(value)])
await read()
}
read()

return [transformStream.readable, transformStream2.readable]
}

export function chainStreams<T>(
streams: ReadableStream<T>[]
): ReadableStream<T> {
Expand Down