Skip to content

Fix hot module reloading for theme development#7673

Open
graygilmore wants to merge 2 commits into
mainfrom
gg-bump-theme-hot-reload
Open

Fix hot module reloading for theme development#7673
graygilmore wants to merge 2 commits into
mainfrom
gg-bump-theme-hot-reload

Conversation

@graygilmore
Copy link
Copy Markdown
Contributor

@graygilmore graygilmore commented May 29, 2026

WHY are these changes introduced?

Fixes Shopify/developer-tools-team#1033.

Hot reload stopped working in the theme editor (Online Store Editor) a while back. With shopify theme dev running, reloading the customizer just logs [HotReload] Connection closed by the server, attempting to reconnect... and never reconnects. It's been reported a few times (community forum threads, dev-tools issue #1033), and an earlier attempt to fix it (#6833) stalled.

There are two separate problems:

  1. The hot-reload client was a few versions behind and didn't trigger a full reload on {% schema %} changes.
  2. The bigger one: the dev server's CORS allowlist was locked down to localhost and the store domain in 226b49e (to close a hole where any website could read from the localhost server). The theme editor renders its preview in an iframe served from https://online-store-web.shopifyapps.com, which opens the hot-reload EventSource back to the local dev server. That origin isn't on the allowlist, so the browser blocks the connection — which is the reconnect loop above.

The dependency bump on its own doesn't fix this — I confirmed the CORS errors on #6833 back in March. The server has to allow the editor's origin too.

WHAT is this pull request doing?

  • Bumps @shopify/theme-hot-reload from 0.0.18 to 0.0.22. On the client side this triggers a full reload on schema changes, restricts the EventSource to known origins, and uses the original storefront domain when calling the Section Rendering API.
  • Adds https://online-store-web.shopifyapps.com to the dev server's CORS allowlist so the theme editor's preview iframe can open the hot-reload connection.
  • Adds tests for the allowlist: editor origin allowed, storefront origin allowed, unknown origins rejected, and no CORS headers on direct navigation (no Origin header).

This intentionally keeps the allowlist approach from 226b49e instead of going back to wildcard CORS, so the original vulnerability stays closed. It also only allowlists the production editor origin.

How to test your changes?

A snapshot has been created for easy testing:

pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260529205834
  1. Install the snapshot (or pull this branch down).
  2. Run shopify theme dev against a store and open the theme editor (use e shortcut).
  3. Edit code locally
  4. Expected: the preview hot reloads and the console logs [HotReload] Connected. Before this change you'd get [HotReload] Connection closed by the server, attempting to reconnect... instead.

Picks up four releases that improve the hot-reload script served to the browser during `theme dev`:

- Prevent EventSource connections to unknown origins
- Use the original storefront domain when calling the Section Rendering API
- Allow messages from the tab opener for theme preview
- Improve stylesheet hot-reloading in the Online Store Editor to avoid full refreshes
@github-actions github-actions Bot added the Area: @shopify/theme @shopify/theme package issues label May 29, 2026
Hot reload stopped working in the theme editor after 226b49e locked the
dev server's CORS allowlist down to localhost and the store domain to close a
vulnerability where any site could read from the localhost server.

The theme editor renders its storefront preview in an iframe served from
https://online-store-web.shopifyapps.com, which opens a hot-reload EventSource
back to the local dev server. That origin wasn't on the allowlist, so the
browser blocked the connection ("Connection closed by the server, attempting
to reconnect...").

Add the Online Store Editor origin to the allowlist so hot reload works in the
editor again, without reopening the wildcard CORS hole.
@graygilmore
Copy link
Copy Markdown
Contributor Author

/snapit

@github-actions
Copy link
Copy Markdown
Contributor

🫰✨ Thanks @graygilmore! Your snapshot has been published to npm.

Test the snapshot by installing your package globally:

pnpm i -g --@shopify:registry=https://registry.npmjs.org @shopify/cli@0.0.0-snapshot-20260529205834

Caution

After installing, validate the version by running shopify version in your terminal.
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

@Shopify Shopify deleted a comment from github-actions Bot May 29, 2026
@graygilmore graygilmore marked this pull request as ready for review May 29, 2026 21:32
@graygilmore graygilmore requested review from a team as code owners May 29, 2026 21:32
@graygilmore graygilmore changed the title Bump @shopify/theme-hot-reload from 0.0.18 to 0.0.22 Fix hot module reloading for theme development May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: @shopify/theme @shopify/theme package issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant