HMR (Hot Module Replacement)¶
Hot Module Replacement (HMR) is a core feature of MageObsidian powered by Vite: it updates your frontend in the browser in real time, without a full reload. This page covers the HMR-specific pieces; for the full day-to-day loop (starting/stopping the server, syncing the env, diagnostics) see Development Workflow.
This is what it feels like β design tokens re-theme the page and a .vue template hot-swaps while the component keeps its state (the search panel never closes):
β οΈ Important Notice HMR is a development-only feature. The HMR flag is ignored when Magento runs in production mode, so there is nothing to undo before going live.
1. Enable HMR¶
HMR is a Magento config flag, toggled with a command β no file editing:
Magento must also be in developer mode (bin/magento deploy:mode:set developer); in production the flag is ignored.
Tip:
bin/magento mage-obsidian:frontend:dev --updoes this in one shot β developer mode, the HMR flag, the.envsync, the cache flush and the dev server β and--downreverses it. See Development Workflow.
2. Configure Nginx¶
The browser must reach the Vite dev server for HMR. Generate the proxy snippet derived from your configuration and paste it into your server block:
The snippet routes Vite's HMR traffic (WebSocket-aware) and the generated assets to the dev server, e.g.:
Place these rules below your existing static-version rewrite (location ~ ^/static/version\d*/ { ... }). The host and port come from your MageObsidian config β you do not hand-pick them; --print-nginx fills them in.
3. Start the Dev Server¶
This syncs the Vite .env from your Magento config and launches the dev server with HMR. Open your storefront β edits to a .vue component, a module.extend.css, or a theme source are reflected instantly. Stop it with --stop, check it with --status. See Development Workflow for the complete command set.
Multi-website with a shared theme¶
When the same theme is served on more than one website (different hosts), each host must reach the dev server over its own origin, or the secondary host gets 403 on Vite's assets and a "Vite dev server is not responding" banner.
VITE_SERVER_ALLOWED_HOSTSβ list every storefront host that serves the theme (comma-separated). Vite answers asset requests only for allowed hosts.MAGENTO_HOSTβ leave it empty for the multi-website case. The HMR websocket host is then derived from the browser'swindow.location, so each website opens a same-originwssconnection. Set a fixed value only when a proxy/tunnel forces one public host for all traffic.
Troubleshooting¶
Run the doctor β it checks app mode, the HMR flag, dev-server reachability, the contract, and the env in one shot:
Common causes when HMR "doesn't update":
- HMR flag off or production mode β
mage-obsidian:frontend:hmr --show; the flag is ignored outside developer mode. - Nginx not proxying to Vite β regenerate and re-paste the snippet with
--print-nginx; confirm the dev server is reachable (--status/ doctor). - Dev server not running β
mage-obsidian:frontend:dev --status, then--start --theme=β¦.
With HMR enabled and the proxy in place, you get instant CSS injection and component updates β no page reloads, no manual rebuilds.