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

perf: lazyload the edge runtime in NextServer #41322

Merged
merged 5 commits into from Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/next/server/next-server.ts
Expand Up @@ -54,7 +54,7 @@ import HttpProxy from 'next/dist/compiled/http-proxy'
import { getPathMatch } from '../shared/lib/router/utils/path-match'
import { createHeaderRoute, createRedirectRoute } from './server-route-utils'
import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-asset-path'
import { run } from './web/sandbox'

import { detectDomainLocale } from '../shared/lib/i18n/detect-domain-locale'

import { NodeNextRequest, NodeNextResponse } from './base-http/node'
Expand All @@ -68,7 +68,6 @@ import { ParsedUrl, parseUrl } from '../shared/lib/router/utils/parse-url'
import { parse as nodeParseUrl } from 'url'
import * as Log from '../build/output/log'
import loadRequireHook from '../build/webpack/require-hook'
import { consumeUint8ArrayReadableStream } from 'next/dist/compiled/edge-runtime'

import BaseServer, {
Options,
Expand Down Expand Up @@ -1766,6 +1765,7 @@ export default class NextNodeServer extends BaseServer {
}

const method = (params.request.method || 'GET').toUpperCase()
const { run } = require('./web/sandbox') as typeof import('./web/sandbox')

const result = await run({
distDir: this.distDir,
Expand Down Expand Up @@ -2089,6 +2089,7 @@ export default class NextNodeServer extends BaseServer {
)
}

const { run } = require('./web/sandbox') as typeof import('./web/sandbox')
const result = await run({
distDir: this.distDir,
name: edgeInfo.name,
Expand Down Expand Up @@ -2129,6 +2130,8 @@ export default class NextNodeServer extends BaseServer {
if (result.response.body) {
// TODO(gal): not sure that we always need to stream
const nodeResStream = (params.res as NodeNextResponse).originalResponse
const { consumeUint8ArrayReadableStream } =
require('next/dist/compiled/edge-runtime') as typeof import('next/dist/compiled/edge-runtime')
try {
for await (const chunk of consumeUint8ArrayReadableStream(
result.response.body
Expand Down