Skip to content

fix: disable HMR for SSR transforms to prevent ERR_LOAD_URL#110

Open
Brooooooklyn wants to merge 1 commit intomainfrom
fix/ssr-hmr-virtual-module-109
Open

fix: disable HMR for SSR transforms to prevent ERR_LOAD_URL#110
Brooooooklyn wants to merge 1 commit intomainfrom
fix/ssr-hmr-virtual-module-109

Conversation

@Brooooooklyn
Copy link
Member

@Brooooooklyn Brooooooklyn commented Mar 13, 2026

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.

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.ssr in the Vite transform hook, skipping template dependency watching, and forcing hmr: false when transforming for SSR.

Adds an SSR-only resolveId/load safety net for @ng/component virtual 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.ts to assert HMR code is injected only when hmr is enabled and that disabling it produces no templateUpdates or @ng/component imports.

Written by Cursor Bugbot for commit fe93bae. This will update automatically on new commits. Configure here.

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>
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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) {

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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.

bug: ERR_LOAD_URL when resolving @ng/component virtual modules in SSR/Nitro context

1 participant