fix: disable HMR for SSR transforms to prevent ERR_LOAD_URL#110
fix: disable HMR for SSR transforms to prevent ERR_LOAD_URL#110Brooooooklyn wants to merge 1 commit intomainfrom
Conversation
When Nitro or other SSR frameworks process server-side code through Vite's module runner, the HMR initialization code would dynamically import @ng/component virtual modules that are only served via HTTP middleware, causing ERR_LOAD_URL failures. - Check options.ssr in transform hook and disable HMR for SSR bundles - Add resolveId/load hooks for @ng/component as safety net in SSR context - Skip file watcher registration for SSR transforms This matches Angular's official behavior where _enableHmr is only set for browser bundles, never for SSR bundles. - Close #109 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe93bae3eb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // DON'T use addWatchFile - it creates modules in Vite's graph! | ||
| // Instead, use our custom watcher that doesn't create modules. | ||
| if (watchMode && viteServer) { | ||
| if (watchMode && viteServer && !isSSR) { |
There was a problem hiding this comment.
Keep SSR resource watchers to invalidate template cache
Removing watcher registration for SSR transforms (!isSSR) means external templates/styles read during SSR are cached but never invalidated on file change, because resourceCache.delete(...) only runs inside the custom fs.watch callback and handleHotUpdate explicitly ignores resource files. In SSR-only code paths (or before any client transform registers watchers), editing templateUrl/styleUrls can leave SSR output stale until a restart.
Useful? React with 👍 / 👎.

When Nitro or other SSR frameworks process server-side code through
Vite's module runner, the HMR initialization code would dynamically
import @ng/component virtual modules that are only served via HTTP
middleware, causing ERR_LOAD_URL failures.
This matches Angular's official behavior where _enableHmr is only set
for browser bundles, never for SSR bundles.
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
Note
Medium Risk
Medium risk because it changes Vite transform behavior and module resolution in SSR mode, which could affect SSR builds and dev-server behavior if SSR detection or virtual module matching is off.
Overview
Prevents SSR bundles from including Angular HMR initialization by detecting
options.ssrin the Vitetransformhook, skipping template dependency watching, and forcinghmr: falsewhen transforming for SSR.Adds an SSR-only
resolveId/loadsafety net for@ng/componentvirtual modules that returns an empty stub module so Vite’s module runner (e.g., Nitro) doesn’t crash when those imports appear.Introduces a new
ssr-hmr.test.tsto assert HMR code is injected only whenhmris enabled and that disabling it produces notemplateUpdatesor@ng/componentimports.Written by Cursor Bugbot for commit fe93bae. This will update automatically on new commits. Configure here.