Skip to content

Commit

Permalink
Cleanup leftover render worker code (#55991)
Browse files Browse the repository at this point in the history
We removed render workers in #54813 -- this PR removes some leftover
things related to that work
  • Loading branch information
ztanner authored Sep 26, 2023
1 parent df12508 commit ecd4299
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 374 deletions.
3 changes: 1 addition & 2 deletions packages/next/src/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import '../server/lib/cpu-profile'
import type { StartServerOptions } from '../server/lib/start-server'
import { getPort, printAndExit } from '../server/lib/utils'
import { RESTART_EXIT_CODE, getPort, printAndExit } from '../server/lib/utils'
import * as Log from '../build/output/log'
import { CliCommand } from '../lib/commands'
import { getProjectDir } from '../lib/get-project-dir'
Expand All @@ -24,7 +24,6 @@ import { initialEnv, loadEnvConfig } from '@next/env'
import { trace } from '../trace'
import { validateTurboNextConfig } from '../lib/turbopack-warning'
import { fork } from 'child_process'
import { RESTART_EXIT_CODE } from '../server/lib/setup-server-worker'
import {
getReservedPortExplanation,
isPortIsReserved,
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/experimental/testmode/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
ProxyResponse,
} from './proxy'
import { ClientRequestInterceptor } from 'next/dist/compiled/@mswjs/interceptors/ClientRequest'
import { WorkerRequestHandler } from '../../server/lib/setup-server-worker'
import { NodeRequestHandler } from '../../server/next-server'
import type { WorkerRequestHandler } from '../../server/lib/types'
import type { NodeRequestHandler } from '../../server/next-server'

interface TestReqInfo {
url: string
Expand Down
6 changes: 0 additions & 6 deletions packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ export interface Options {
*/
httpServer?: import('http').Server

_routerWorker?: boolean
_renderWorker?: boolean

isNodeDebugging?: 'brk' | boolean
}

Expand Down Expand Up @@ -373,7 +370,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
public readonly matchers: RouteMatcherManager
protected readonly i18nProvider?: I18NProvider
protected readonly localeNormalizer?: LocaleRouteNormalizer
protected readonly isRenderWorker?: boolean

public constructor(options: ServerOptions) {
const {
Expand All @@ -388,7 +384,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} = options

this.serverOptions = options
this.isRenderWorker = options._renderWorker

this.dir =
process.env.NEXT_RUNTIME === 'edge' ? dir : require('path').resolve(dir)
Expand Down Expand Up @@ -2640,7 +2635,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
const invokeOutput = ctx.req.headers['x-invoke-output']
if (
!this.minimalMode &&
this.isRenderWorker &&
typeof invokeOutput === 'string' &&
isDynamicRoute(invokeOutput || '') &&
invokeOutput !== match.definition.pathname
Expand Down
46 changes: 13 additions & 33 deletions packages/next/src/server/dev/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,16 +487,10 @@ export default class DevServer extends Server {
err?: unknown,
type?: 'unhandledRejection' | 'uncaughtException' | 'warning' | 'app-dir'
): Promise<void> {
if (this.isRenderWorker) {
await this.invokeDevMethod({
method: 'logErrorWithOriginalStack',
args: [err, type],
})
return
}
throw new Error(
'Invariant logErrorWithOriginalStack called outside render worker'
)
await this.invokeDevMethod({
method: 'logErrorWithOriginalStack',
args: [err, type],
})
}

protected getPagesManifest(): PagesManifest | undefined {
Expand Down Expand Up @@ -731,10 +725,6 @@ export default class DevServer extends Server {
appPaths?: ReadonlyArray<string> | null
match?: RouteMatch
}): Promise<void> {
if (!this.isRenderWorker) {
throw new Error('Invariant ensurePage called outside render worker')
}

await this.invokeDevMethod({
method: 'ensurePage',
args: [opts],
Expand Down Expand Up @@ -795,27 +785,17 @@ export default class DevServer extends Server {
}

protected async getFallbackErrorComponents(): Promise<LoadComponentsReturnType | null> {
if (this.isRenderWorker) {
await this.invokeDevMethod({
method: 'getFallbackErrorComponents',
args: [],
})
return await loadDefaultErrorComponents(this.distDir)
}
throw new Error(
`Invariant getFallbackErrorComponents called outside render worker`
)
await this.invokeDevMethod({
method: 'getFallbackErrorComponents',
args: [],
})
return await loadDefaultErrorComponents(this.distDir)
}

async getCompilationError(page: string): Promise<any> {
if (this.isRenderWorker) {
return await this.invokeDevMethod({
method: 'getCompilationError',
args: [page],
})
}
throw new Error(
'Invariant getCompilationError called outside render worker'
)
return await this.invokeDevMethod({
method: 'getCompilationError',
args: [page],
})
}
}
3 changes: 0 additions & 3 deletions packages/next/src/server/lib/render-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export async function initialize(opts: {
dev: boolean
minimalMode?: boolean
hostname?: string
workerType: 'router' | 'render'
isNodeDebugging: boolean
keepAliveTimeout?: number
serverFields?: any
Expand All @@ -97,8 +96,6 @@ export async function initialize(opts: {

const app = next({
...opts,
_routerWorker: opts.workerType === 'router',
_renderWorker: opts.workerType === 'render',
hostname: opts.hostname || 'localhost',
customServer: false,
httpServer: opts.server,
Expand Down
95 changes: 46 additions & 49 deletions packages/next/src/server/lib/route-resolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { NextConfigComplete } from '../config-shared'
import type { IncomingMessage, ServerResponse } from 'http'
import type { RenderServer } from './router-server'

import '../require-hook'
import '../node-polyfill-fetch'
Expand All @@ -18,7 +19,6 @@ import { PERMANENT_REDIRECT_STATUS } from '../../shared/lib/constants'
import { formatHostname } from './format-hostname'
import { signalFromNodeResponse } from '../web/spec-extension/adapters/next-request'
import { getMiddlewareRouteMatcher } from '../../shared/lib/router/utils/middleware-route-matcher'
import type { RenderWorker } from './router-server'
import { pipeReadable } from '../pipe-readable'

type RouteResult =
Expand Down Expand Up @@ -125,57 +125,54 @@ export async function makeResolver(
hostname,
isNodeDebugging: false,
dev: true,
workerType: 'render',
},
{
pages: {
async initialize() {
return {
async requestHandler(req, res) {
if (!req.headers['x-middleware-invoke']) {
throw new Error(`Invariant unexpected request handler call`)
}

const cloneableBody = getCloneableBody(req)
const { run } =
require('../web/sandbox') as typeof import('../web/sandbox')

const result = await run({
distDir,
name: middlewareInfo.name || '/',
paths: middlewareInfo.paths || [],
edgeFunctionEntry: middlewareInfo,
request: {
headers: req.headers,
method: req.method || 'GET',
nextConfig: {
i18n: nextConfig.i18n,
basePath: nextConfig.basePath,
trailingSlash: nextConfig.trailingSlash,
},
url: `http://${fetchHostname}:${port}${req.url}`,
body: cloneableBody,
signal: signalFromNodeResponse(res),
async initialize() {
return {
async requestHandler(req, res) {
if (!req.headers['x-middleware-invoke']) {
throw new Error(`Invariant unexpected request handler call`)
}

const cloneableBody = getCloneableBody(req)
const { run } =
require('../web/sandbox') as typeof import('../web/sandbox')

const result = await run({
distDir,
name: middlewareInfo.name || '/',
paths: middlewareInfo.paths || [],
edgeFunctionEntry: middlewareInfo,
request: {
headers: req.headers,
method: req.method || 'GET',
nextConfig: {
i18n: nextConfig.i18n,
basePath: nextConfig.basePath,
trailingSlash: nextConfig.trailingSlash,
},
useCache: true,
onWarning: console.warn,
})

const err = new Error()
;(err as any).result = result
throw err
},
async upgradeHandler() {
throw new Error(`Invariant: unexpected upgrade handler call`)
},
}
},
deleteAppClientCache() {},
async deleteCache() {},
async clearModuleContext() {},
async propagateServerField() {},
} as Partial<RenderWorker> as any,
},
url: `http://${fetchHostname}:${port}${req.url}`,
body: cloneableBody,
signal: signalFromNodeResponse(res),
},
useCache: true,
onWarning: console.warn,
})

const err = new Error()
;(err as any).result = result
throw err
},
async upgradeHandler() {
throw new Error(`Invariant: unexpected upgrade handler call`)
},
}
},
deleteAppClientCache() {},
async deleteCache() {},
async clearModuleContext() {},
async propagateServerField() {},
} as Partial<RenderServer> as any,
{} as any
)

Expand Down
Loading

0 comments on commit ecd4299

Please sign in to comment.