Skip to content

fix(vite-plugin): respect Vite's server.hmr setting when compiling components - #743

Open
nagahara-naoki wants to merge 1 commit into
voidzero-dev:mainfrom
nagahara-naoki:fix/vitest-hmr
Open

nagahara-naoki wants to merge 1 commit into
voidzero-dev:mainfrom
nagahara-naoki:fix/vitest-hmr

Conversation

@nagahara-naoki

Copy link
Copy Markdown
Contributor

Problem

Running vitest run with @oxc-angular/vite in jsdom or happy-dom can exit with code 1 even when all tests pass.

Vitest runs Vite in serve mode with server.hmr set to false. The Angular plugin still emits a component HMR initializer for client transforms. When a test imports the component, the initializer tries to load @ng/component, and Vitest reports an unhandled ERR_MODULE_NOT_FOUND.

Fix

Skip the component HMR initializer when Vite’s resolved server.hmr setting is false. This lets the same Vite config work for development and tests without setting liveReload: false specifically for Vitest.

Verification

  • Added a regression test that compiles a component in serve mode with server.hmr: false and checks that the output contains the Angular component definition and omits the HMR initializer.
  • Reproduced the failure with a single component and a single test on @oxc-angular/vite 0.0.46, Angular 22.3.0, Vite 8.3.4, and Vitest 5.0.3. Both jsdom and happy-dom exited with code 1 before the fix and code 0 after it.
  • All 580 plugin tests and 10 Chromium HMR end-to-end tests passed, including updates to external templates, inline templates, and CSS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant