Skip to content

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

Merged
Brooooooklyn merged 2 commits intomainfrom
fix/ssr-hmr-virtual-module-109
Mar 14, 2026
Merged

fix: disable HMR for SSR transforms to prevent ERR_LOAD_URL#110
Brooooooklyn merged 2 commits intomainfrom
fix/ssr-hmr-virtual-module-109

Conversation

@Brooooooklyn
Copy link
Copy Markdown
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
Touches Vite transform and module resolution behavior for SSR vs client builds; mis-detection of ssr or the new virtual-module handling could change dev-server/SSR runtime behavior.

Overview
Prevents SSR bundles from including Angular HMR bootstrapping that imports @ng/component virtual modules, by passing Vite’s options.ssr into the transform handler and forcing hmr: false for SSR transforms.

Adds an SSR-only resolveId/load safety net for @ng/component to return an empty virtual module when Vite’s module runner resolves these imports, avoiding ERR_LOAD_URL crashes in Nitro/SSR environments.

Introduces new ssr-hmr.test.ts coverage asserting HMR code is injected only when explicitly enabled and that hmr: false yields no template updates or @ng/component references.

Written by Cursor Bugbot for commit 153de34. 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
Copy Markdown
Member Author

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

Copy link
Copy Markdown

@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".

The fs.watch callback serves dual purpose: (1) invalidating
resourceCache on file change, and (2) sending HMR WebSocket events.
The HMR part is already independently gated by componentIds, which
are only populated for client transforms. Skipping watcher
registration for SSR would leave resourceCache stale when external
templates/styles change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn merged commit 170436f into main Mar 14, 2026
4 checks passed
@Brooooooklyn Brooooooklyn deleted the fix/ssr-hmr-virtual-module-109 branch March 14, 2026 04:42
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