Skip to content

fix(workbench): claim lock when developing workbench remote#1387

Merged
gu-stav merged 3 commits into
mainfrom
fix/workbench-remote-dev-coordinator
Jun 25, 2026
Merged

fix(workbench): claim lock when developing workbench remote#1387
gu-stav merged 3 commits into
mainfrom
fix/workbench-remote-dev-coordinator

Conversation

@gu-stav

@gu-stav gu-stav commented Jun 25, 2026

Copy link
Copy Markdown
Member

Description

The workbench remote runs as a plain sanity dev (it can't render itself), so it never claimed the workbench lock or the dev-server registry. Two fallouts:

  • It announced a bare App dev server started on port 5173 — no clickable URL.
  • Running sanity dev for dev apps saw no running workbench, so each started its own shell instead of registering into the remote.

Now the workbench remote claims the lock and bridges the registry, and the plain app server prints a clickable URL. Apps discover the remote and register into it.

I've used that opportunity to move even more code into the workbench-cli package.

Testing

Verified against sanity-io/workbench#262: the remote claims workbench.lock and prints a clickable URL, and a favorites dev run reports Workbench dev server started at http://localhost:5173 (app on port 5174). No automated coverage for the multi-process dev orchestration yet.


Note

Medium Risk
Changes multi-process workbench dev orchestration (lock, registry, HMR bridge); scope is dev-only but incorrect behavior could still break local federation workflows.

Overview
Workbench remote sanity dev no longer bypasses workbench orchestration in devAction—every workbench app goes through startWorkbenchDev, which handles the remote internally.

When SANITY_INTERNAL_IS_WORKBENCH_REMOTE is set, startWorkbenchDev starts a plain app/studio server and attaches startWorkbenchRemoteCoordinator, which claims the workbench lock (when free) and bridges the dev-server registry into the Vite HMR channel via shared attachViteDevServerBridge logic (extracted from the full workbench shell path). Other app sanity dev runs can discover the remote and register instead of each spawning its own shell.

startAppDevServer now prints a styled, clickable http://… URL for workbench apps that announce their own URL, using toDisplayHost so bind addresses like 0.0.0.0 show as localhost. Tests and a changeset cover the routing and logging updates.

Reviewed by Cursor Bugbot for commit 936949a. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against fix/workbench-mf-remoteentry (bc2931ac)

@sanity/cli

Metric Value vs fix/workbench-mf-remoteentry (bc2931a)
Internal (raw) 2.7 KB -
Internal (gzip) 1.0 KB -
Bundled (raw) 11.16 MB -
Bundled (gzip) 2.10 MB -
Import time 870ms -2ms, -0.2%

bin:sanity

Metric Value vs fix/workbench-mf-remoteentry (bc2931a)
Internal (raw) 782 B -
Internal (gzip) 423 B -
Bundled (raw) 9.87 MB -
Bundled (gzip) 1.78 MB -
Import time 2.23s -10ms, -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 fix/workbench-mf-remoteentry (bc2931ac)

Metric Value vs fix/workbench-mf-remoteentry (bc2931a)
Internal (raw) 106.7 KB -
Internal (gzip) 26.7 KB -
Bundled (raw) 21.72 MB -
Bundled (gzip) 3.46 MB -
Import time 773ms +1ms, +0.1%

🗺️ 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 fix/workbench-mf-remoteentry (bc2931ac)

Metric Value vs fix/workbench-mf-remoteentry (bc2931a)
Internal (raw) 908 B -
Internal (gzip) 483 B -
Bundled (raw) 931 B -
Bundled (gzip) 491 B -
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.

@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Preview this PR with pkg.pr.new

Run the Sanity CLI

npx https://pkg.pr.new/sanity-io/cli/@sanity/cli@936949a <command>

...Or upgrade project dependencies

📦 @sanity/cli
pnpm install https://pkg.pr.new/@sanity/cli@936949a
📦 @sanity/cli-build
pnpm install https://pkg.pr.new/@sanity/cli-build@936949a
📦 @sanity/cli-core
pnpm install https://pkg.pr.new/@sanity/cli-core@936949a
📦 @sanity/cli-test
pnpm install https://pkg.pr.new/@sanity/cli-test@936949a
📦 @sanity/eslint-config-cli
pnpm install https://pkg.pr.new/@sanity/eslint-config-cli@936949a
📦 @sanity/workbench-cli
pnpm install https://pkg.pr.new/@sanity/workbench-cli@936949a

View Commit (936949a)

@gu-stav gu-stav force-pushed the fix/workbench-remote-dev-coordinator branch 3 times, most recently from fa76352 to 6e3f89d Compare June 25, 2026 11:33
@gu-stav gu-stav changed the title fix(workbench): run the workbench remote dev server as the machine's workbench fix(workbench): claim lockfile when developing workbench remote Jun 25, 2026
@github-actions

github-actions Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli/src/actions/dev/devAction.ts 76.9% (- 1.6%)
packages/@sanity/cli/src/actions/dev/servers/startAppDevServer.ts 96.8% (- 3.2%)
packages/@sanity/workbench-cli/src/actions/dev/startWorkbenchDev.ts 81.0% (- 14.8%)
packages/@sanity/workbench-cli/src/actions/dev/startWorkbenchDevServer.ts 89.1% (- 9.6%)

Comparing 4 changed files against main @ 1b7bf66260e5c55a1e7a207e3bc2f9bac78bf4da

Overall Coverage

Metric Coverage
Statements 74.3% (- 0.1%)
Branches 64.1% (- 0.1%)
Functions 69.0% (- 0.0%)
Lines 74.8% (- 0.1%)

The #RUNTIME-002 fix landed in module-federation/vite#854 (findRemoteEntryFile
resolves the manifest's remoteEntry to the container, not a same-named ./App
expose). 1.16.11 (#850) didn't carry it, so pin the #854 preview until release.
@gu-stav gu-stav force-pushed the fix/workbench-mf-remoteentry branch from 70efbab to bc2931a Compare June 25, 2026 12:05
gu-stav added 2 commits June 25, 2026 14:06
…workbench

The remote takes a plain dev path (it can't render itself), so it never claimed
the lock or registry — every app dev run started its own workbench shell, and
the remote logged a bare port.

devAction now routes every workbench app to startWorkbenchDev, which runs the
remote as a plain app server that still claims the singleton lock and bridges
the registry (shared with the shell via attachViteDevServerBridge). That plain
server also announces a clickable URL.
mockAppServer returned the full union, so server/close access failed and the
start mock did not satisfy StartAppServer — the type-check errored. Type the
mock as the started arm and the helper param as StartAppServer.
@gu-stav gu-stav force-pushed the fix/workbench-remote-dev-coordinator branch from 6e3f89d to 936949a Compare June 25, 2026 12:07
@gu-stav gu-stav marked this pull request as ready for review June 25, 2026 12:20
@gu-stav gu-stav requested a review from a team as a code owner June 25, 2026 12:20
@gu-stav gu-stav requested a review from joshuaellis June 25, 2026 12:20
@gu-stav gu-stav changed the title fix(workbench): claim lockfile when developing workbench remote fix(workbench): claim lock when developing workbench remote Jun 25, 2026
@gu-stav gu-stav changed the base branch from fix/workbench-mf-remoteentry to main June 25, 2026 13:04
@gu-stav gu-stav merged commit cb80a56 into main Jun 25, 2026
61 of 62 checks passed
@gu-stav gu-stav deleted the fix/workbench-remote-dev-coordinator branch June 25, 2026 13:21
@cursor cursor Bot mentioned this pull request Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants