Skip to content

feat(dev): enable react-refresh for shared dev-server HMR#913

Merged
gu-stav merged 1 commit intofeat/workbenchfrom
feat/SDK-1187
Apr 10, 2026
Merged

feat(dev): enable react-refresh for shared dev-server HMR#913
gu-stav merged 1 commit intofeat/workbenchfrom
feat/SDK-1187

Conversation

@joshuaellis
Copy link
Copy Markdown
Member

Summary

  • Passes reactRefreshHost to @vitejs/plugin-react so federated Studio/App modules connect their react-refresh preamble to the workbench host dev server
  • When the workbench is running (federation enabled), devAction.ts computes the workbench URL and threads it through startStudioDevServer/startAppDevServerstartDevServergetViteConfigviteReact({reactRefreshHost})
  • Enables component-level HMR across the module federation boundary

Closes SDK-1187

@joshuaellis joshuaellis requested a review from a team as a code owner April 9, 2026 20:09
@joshuaellis joshuaellis requested review from binoy14 and removed request for a team April 9, 2026 20:09
@joshuaellis joshuaellis requested review from gu-stav and removed request for binoy14 April 9, 2026 20:11
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

📦 Bundle Stats — @sanity/cli

Compared against feat/workbench (e04493e2)

@sanity/cli

Metric Value vs feat/workbench (e04493e)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.95 MB -
Bundled (gzip) 2.06 MB -
Import time 818ms -9ms, -1.0%

bin:sanity

Metric Value vs feat/workbench (e04493e)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 2.23s -9ms, -0.4%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against feat/workbench (e04493e2)

Metric Value vs feat/workbench (e04493e)
Internal (raw) 92.4 KB -
Internal (gzip) 21.6 KB -
Bundled (raw) 21.53 MB -
Bundled (gzip) 3.41 MB -
Import time 781ms -4ms, -0.5%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against feat/workbench (e04493e2)

Metric Value vs feat/workbench (e04493e)
Internal (raw) 976 B -
Internal (gzip) 507 B -
Bundled (raw) 50.7 KB -
Bundled (gzip) 12.6 KB -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@joshuaellis joshuaellis changed the title feat(dev): enable react-refresh for shared dev-server HMR [SDK-1187] feat(dev): enable react-refresh for shared dev-server HMR Apr 9, 2026
@claude
Copy link
Copy Markdown

claude bot commented Apr 9, 2026

Claude finished @gu-stav's task in 2m 31s —— View job


Review

  • Read CLAUDE.md and gather context
  • Get PR diff
  • Review changed files
  • Check changeset

Missing changeset

This PR modifies packages/@sanity/cli with new runtime behavior (react-refresh HMR across the module federation boundary), but no changeset file is included. A patch or minor changeset for @sanity/cli is required. Fix this →

0.0.0.0 produces an unusable reactRefreshHost URL

In devAction.ts:27:

`http://${httpHost || 'localhost'}:${workbenchPort}`

httpHost can be '0.0.0.0' (e.g. when the user passes --host 0.0.0.0). Since it's truthy, the fallback doesn't apply and the browser receives http://0.0.0.0:3333 as the react-refresh endpoint, which won't connect. The same pattern exists at line 61 for the logged workbench URL, but that's cosmetic; reactRefreshHost is consumed by the browser and the connection will silently fail. The fix is to normalize 0.0.0.0localhost before constructing the URL:

const resolvedHost = (!httpHost || httpHost === '0.0.0.0') ? 'localhost' : httpHost
const reactRefreshHost = closeWorkbenchServer === undefined
  ? undefined
  : `http://${resolvedHost}:${workbenchPort}`

Fix this →

Pass `reactRefreshHost` to `@vitejs/plugin-react` so federated Studio
modules connect their react-refresh preamble to the workbench host,
enabling component-level HMR across the module federation boundary.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gu-stav
Copy link
Copy Markdown
Member

gu-stav commented Apr 10, 2026

@joshuaellis Fixed the lockfile in the feature branch and rebased this branch.

@gu-stav gu-stav merged commit a9bb816 into feat/workbench Apr 10, 2026
42 checks passed
@gu-stav gu-stav deleted the feat/SDK-1187 branch April 10, 2026 06:59
@github-actions
Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-core/src/config/cli/schemas.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/build/buildApp.ts 94.9% (±0%)
packages/@sanity/cli/src/actions/build/buildStaticFiles.ts 97.3% (+ 0.7%)
packages/@sanity/cli/src/actions/build/buildStudio.ts 97.5% (±0%)
packages/@sanity/cli/src/actions/build/getViteConfig.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/dev/devAction.ts 90.0% (- 10.0%)
packages/@sanity/cli/src/actions/dev/getDevServerConfig.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/dev/startAppDevServer.ts 82.3% (- 4.6%)
packages/@sanity/cli/src/actions/dev/startStudioDevServer.ts 93.3% (- 1.7%)
packages/@sanity/cli/src/actions/dev/startWorkbenchDevServer.ts 96.4% (new)
packages/@sanity/cli/src/actions/dev/writeWorkbenchRuntime.ts 100.0% (new)
packages/@sanity/cli/src/commands/dev.ts 100.0% (±0%)
packages/@sanity/cli/src/server/devServer.ts 94.1% (±0%)

Comparing 13 changed files against main @ ce65da6d7c36c721926c955d2a466dcffb25a4f1

Overall Coverage

Metric Coverage
Statements 83.0% (- 0.0%)
Branches 73.0% (+ 0.0%)
Functions 83.2% (- 0.1%)
Lines 83.5% (±0%)

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.

2 participants