HMR is broken: Vite shows websocket error using react embedded app when using --use-localhost

When using --use-localhost the app loads (app is embedded using react + vite) and I can see the app frontend.

But I noticed that vite gives this websocket error,


After this, if I make any changes to the code, HMR is broken. Vite tries to update, but I do not see those changes in the app, it continues to show the initial load.

This is almost same vite configuration and most of the code is similar to this codebase,

OS: MacOS
shopify.web.toml is

roles = ["frontend"]

[commands]
dev = "npm run dev"
build = "npm run build"

Hey Sam,

We’re looking into this as a possible issue on our side. Will update here asap.

1 Like

Hey Sam! Sorry for the delayed reply. I created a basic app using that same Vite config, and I was able to reproduce the issue. The problem is these lines, which don’t account for a port in the URL:

You can resolve the issue by replacing the const host definition with the cleaner approach from the Remix template:

Let us know if this fixes it for you as well.

1 Like

Yes, this solves the issue. Thank you!