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

feat: enable HMR by default on ModuleRunner side #18749

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions docs/guide/api-environment-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,10 @@ export interface ModuleRunnerOptions {
| InterceptorOptions
/**
* Disable HMR or configure HMR options.
*
* @default true
*/
hmr?:
| false
| {
/**
* Configure HMR logger.
*/
logger?: false | HMRLogger
}
Comment on lines 191 to -201
Copy link
Member Author

@sapphi-red sapphi-red Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document was stale.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModuleRunnerHmr is not mentioned anywhere on this page. Should we add a type for it?

serverModuleRunner also has logger?: instead of ModuleRunnerHmr

hmr?: boolean | ModuleRunnerHmr
/**
* Custom module cache. If not provided, it creates a separate module
* cache for each module runner instance.
Expand Down Expand Up @@ -356,6 +351,7 @@ export const runner = new ModuleRunner(
return response.json()
},
},
hmr: false, // disable HMR as HMR requires transport.connect
},
new ESModulesEvaluator(),
)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ const moduleRunnerConfig = defineConfig({
],
plugins: [
...createSharedNodePlugins({ esbuildOptions: { minifySyntax: true } }),
bundleSizeLimit(53),
bundleSizeLimit(54),
],
})

Expand Down
9 changes: 5 additions & 4 deletions packages/vite/src/module-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ export class ModuleRunner {
this.root = root[root.length - 1] === '/' ? root : `${root}/`
this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules()
this.transport = normalizeModuleRunnerTransport(options.transport)
if (options.hmr) {
if (options.hmr !== false) {
const optionsHmr = options.hmr ?? true
const resolvedHmrLogger: HMRLogger =
options.hmr === true || options.hmr.logger === undefined
optionsHmr === true || optionsHmr.logger === undefined
? hmrLogger
: options.hmr.logger === false
: optionsHmr.logger === false
? silentConsole
: options.hmr.logger
: optionsHmr.logger
this.hmrClient = new HMRClient(
resolvedHmrLogger,
this.transport,
Expand Down
2 changes: 2 additions & 0 deletions packages/vite/src/module-runner/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export interface ModuleRunnerOptions {
| InterceptorOptions
/**
* Disable HMR or configure HMR options.
*
* @default true
*/
hmr?: boolean | ModuleRunnerHmr
/**
Expand Down