diff --git a/packages/vite/src/node/server/environments/runnableEnvironment.ts b/packages/vite/src/node/server/environments/runnableEnvironment.ts index c47298a22920f6..0568214e0b647d 100644 --- a/packages/vite/src/node/server/environments/runnableEnvironment.ts +++ b/packages/vite/src/node/server/environments/runnableEnvironment.ts @@ -2,6 +2,7 @@ import type { ModuleRunner } from 'vite/module-runner' import type { ResolvedConfig } from '../../config' import type { DevEnvironmentContext } from '../environment' import { DevEnvironment } from '../environment' +import type { ServerModuleRunnerOptions } from '../../ssr/runtime/serverModuleRunner' import { createServerModuleRunner } from '../../ssr/runtime/serverModuleRunner' import type { HotChannel } from '../hmr' import { createServerHotChannel } from '../hmr' @@ -21,7 +22,7 @@ export function createRunnableDevEnvironment( export interface RunnableDevEnvironmentContext extends Omit { - runner?: (environment: RunnableDevEnvironment) => ModuleRunner + runnerOptions?: ServerModuleRunnerOptions hot?: false | HotChannel } @@ -33,9 +34,7 @@ export function isRunnableDevEnvironment( class RunnableDevEnvironment extends DevEnvironment { private _runner: ModuleRunner | undefined - private _runnerFactory: - | ((environment: RunnableDevEnvironment) => ModuleRunner) - | undefined + private _runnerOptions: ServerModuleRunnerOptions | undefined constructor( name: string, @@ -43,18 +42,14 @@ class RunnableDevEnvironment extends DevEnvironment { context: RunnableDevEnvironmentContext, ) { super(name, config, context as DevEnvironmentContext) - this._runnerFactory = context.runner + this._runnerOptions = context.runnerOptions } get runner(): ModuleRunner { if (this._runner) { return this._runner } - if (this._runnerFactory) { - this._runner = this._runnerFactory(this) - return this._runner - } - this._runner = createServerModuleRunner(this) + this._runner = createServerModuleRunner(this, this._runnerOptions) return this._runner } } diff --git a/playground/hmr-ssr/__tests__/hmr-ssr.spec.ts b/playground/hmr-ssr/__tests__/hmr-ssr.spec.ts index f6684242a2ea81..7456aca531d468 100644 --- a/playground/hmr-ssr/__tests__/hmr-ssr.spec.ts +++ b/playground/hmr-ssr/__tests__/hmr-ssr.spec.ts @@ -15,7 +15,6 @@ import { createRunnableDevEnvironment, createServer, createServerHotChannel, - createServerModuleRunner, } from 'vite' import type { ModuleRunner } from 'vite/module-runner' import { @@ -1067,8 +1066,7 @@ async function setupModuleRunner( dev: { createEnvironment(name, config) { return createRunnableDevEnvironment(name, config, { - runner: (env) => - createServerModuleRunner(env, { hmr: { logger } }), + runnerOptions: { hmr: { logger } }, hot: createServerHotChannel(), }) },