Skip to content

Commit

Permalink
Initialize experimental Node.js Streams support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Arrowood committed Apr 24, 2024
1 parent e078fd1 commit fbc198c
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
continueStaticPrerender,
continueDynamicHTMLResume,
continueDynamicDataResume,
} from '../stream-utils/node-web-streams-helper'
} from '../stream-utils'
import { canSegmentBeOverridden } from '../../client/components/match-segments'
import { stripInternalQueries } from '../internal-utils'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
encodeReply,
} from 'react-server-dom-webpack/client.edge'

import { streamToString } from '../stream-utils/node-web-streams-helper'
import { streamToString } from '../stream-utils'
import {
arrayBufferToString,
decrypt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
getRedirectStatusCodeFromError,
} from '../../client/components/redirect'
import { renderToReadableStream } from 'react-dom/server.edge'
import { streamToString } from '../stream-utils/node-web-streams-helper'
import { streamToString } from '../stream-utils'
import { RedirectStatusCode } from '../../client/components/redirect-status-code'
import { addPathPrefix } from '../../shared/lib/router/utils/add-path-prefix'

Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/render-to-string.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { streamToString } from '../stream-utils/node-web-streams-helper'
import { streamToString } from '../stream-utils'
import { AppRenderSpan } from '../lib/trace/constants'
import { getTracer } from '../lib/trace/tracer'

Expand Down
6 changes: 1 addition & 5 deletions packages/next/src/server/render-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import type { OutgoingHttpHeaders, ServerResponse } from 'http'
import type { Revalidate } from './lib/revalidate'
import type { FetchMetrics } from './base-http'

import {
chainStreams,
streamFromString,
streamToString,
} from './stream-utils/node-web-streams-helper'
import { chainStreams, streamFromString, streamToString } from './stream-utils'
import { isAbortError, pipeToNodeResponse } from './pipe-readable'

type ContentTypeOption = string | undefined
Expand Down
7 changes: 2 additions & 5 deletions packages/next/src/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type {
SizeLimit,
} from '../types'
import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './stream-utils/node-web-streams-helper'
import type { ReactReadableStream } from './stream-utils'
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../build/webpack/plugins/next-font-manifest-plugin'
import type { PagesModule } from './future/route-modules/pages/module'
Expand Down Expand Up @@ -80,10 +80,7 @@ import { getRequestMeta } from './request-meta'
import { allowedStatusCodes, getRedirectStatus } from '../lib/redirect-status'
import RenderResult, { type PagesRenderResultMetadata } from './render-result'
import isError from '../lib/is-error'
import {
streamToString,
renderToInitialFizzStream,
} from './stream-utils/node-web-streams-helper'
import { streamToString, renderToInitialFizzStream } from './stream-utils'
import { ImageConfigContext } from '../shared/lib/image-config-context.shared-runtime'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import { stripInternalQueries } from './internal-utils'
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/stream-utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './stream-utils.edge'
8 changes: 8 additions & 0 deletions packages/next/src/server/stream-utils/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
if (
process.env.NEXT_RUNTIME === 'nodejs' &&
process.env.EXPERIMENTAL_NODE_STREAMS_SUPPORT
) {
module.exports = require('next/dist/server/stream-utils/stream-utils.edge.js')
} else {
module.exports = require('next/dist/server/stream-utils/stream-utils.node.js')
}
6 changes: 6 additions & 0 deletions packages/next/src/server/stream-utils/stream-utils.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* By default, this file exports the methods from streams-utils.edge since all of those are based on Node.js web streams.
* This file will then be an incremental re-implementation of all of those methods into Node.js only versions (based on proper Node.js Streams).
*/

export * from './stream-utils.edge'

0 comments on commit fbc198c

Please sign in to comment.