Skip to content

fix(workbench): watch for changes of the cli config file#1022

Merged
gu-stav merged 2 commits intofeat/workbenchfrom
fix/workbench-cli-cache
Apr 28, 2026
Merged

fix(workbench): watch for changes of the cli config file#1022
gu-stav merged 2 commits intofeat/workbenchfrom
fix/workbench-cli-cache

Conversation

@gu-stav
Copy link
Copy Markdown
Member

@gu-stav gu-stav commented Apr 28, 2026

Description

While recording the demo I noticed changing the title in a CLI config file for an SDK didn't make it through into workbench. This is happening because the CLI config is cached and only read once.

This PR adds a new method to read a fresh config file every time and initializes the same watcher we are using for the studio config file already. Now updating the title in the CLI config is reflected almost immediately in the dock.


Note

Medium Risk
Introduces an uncached sanity.cli.(ts|js) loader that clears Node’s module cache and wires core-app dev mode into the manifest watcher, which could affect dev-server stability/perf if cache invalidation or watch triggers behave unexpectedly.

Overview
Workbench/core-app dev now tracks edits to sanity.cli.(ts|js) so changes like title/icon propagate without restarting.

This adds getCliConfigUncached() in @sanity/cli-core to bypass both the in-memory config cache and Node/jiti require.cache, updates core-app manifest extraction to use it, and switches devAction to always run startDevManifestWatcher (now generic and extractor-injected) for both studios and core apps, with tests updated/expanded to cover the new watch/extract wiring.

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

@gu-stav gu-stav requested a review from joshuaellis April 28, 2026 14:26
@gu-stav gu-stav requested a review from a team as a code owner April 28, 2026 14:26
@claude
Copy link
Copy Markdown

claude Bot commented Apr 28, 2026

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


Review

  • Gather context
  • Read changed files
  • Check for changeset
  • Post review feedback

Missing changeset

No .changeset/*.md file was added in this PR. This PR has two user-facing changes that require one:

  1. @sanity/cli-core exports a new getCliConfigUncached function (new public API)
  2. @sanity/cli behavioral fix — core-app title/icon now updates in workbench without restart

A patch bump is appropriate for the fix. Example changeset for @sanity/cli:

---
"@sanity/cli": patch
"@sanity/cli-core": patch
---

Workbench now reflects changes to `sanity.cli.ts` title and icon immediately during `sanity dev`.

Cache eviction relies on jiti's CJS registration key matching configPath exactly

packages/@sanity/cli-core/src/config/cli/getCliConfig.ts:84-85

const cjsRequire = createRequire(import.meta.url)
delete cjsRequire.cache[configPath]

This is correct for jiti's current CJS transform behaviour, but it's fragile: if jiti ever changes how it registers files (e.g. using a derived key, adding a URL prefix, or switching to ESM-native caching), repeated calls to getCliConfigUncached would silently return stale data. There's no test verifying the cache is actually cleared between calls. If a unit test for getCliConfigUncached already exists elsewhere or is out of scope here, this is low priority — but it's worth a note in the existing test file or a targeted integration test covering the "second call returns fresh data" case.

Fix this →

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

📦 Bundle Stats — @sanity/cli

Compared against feat/workbench (9f660ec0)

@sanity/cli

Metric Value vs feat/workbench (9f660ec)
Internal (raw) 2.1 KB -
Internal (gzip) 799 B -
Bundled (raw) 10.94 MB -
Bundled (gzip) 2.05 MB -
Import time 876ms +14ms, +1.7%

bin:sanity

Metric Value vs feat/workbench (9f660ec)
Internal (raw) 975 B -
Internal (gzip) 460 B -
Bundled (raw) 9.84 MB -
Bundled (gzip) 1.77 MB -
Import time 2.47s +55ms, +2.3%

🗺️ 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 (9f660ec0)

Metric Value vs feat/workbench (9f660ec)
Internal (raw) 95.5 KB +1.4 KB, +1.5%
Internal (gzip) 22.5 KB +422 B, +1.9%
Bundled (raw) 21.62 MB +1.4 KB, +0.0%
Bundled (gzip) 3.42 MB +485 B, +0.0%
Import time 845ms +24ms, +2.9%

🗺️ 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 (9f660ec0)

Metric Value vs feat/workbench (9f660ec)
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.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli-core/src/config/cli/getCliConfig.ts 100.0% (±0%)
packages/@sanity/cli-core/src/config/cli/schemas.ts 100.0% (±0%)
packages/@sanity/cli-core/src/services/cliUserConfig.ts 100.0% (±0%)
packages/@sanity/cli-core/src/util/getSanityConfigDir.ts 66.7% (new)
packages/@sanity/cli/src/actions/build/buildApp.ts 94.9% (±0%)
packages/@sanity/cli/src/actions/build/buildStaticFiles.ts 97.6% (+ 1.0%)
packages/@sanity/cli/src/actions/build/buildStudio.ts 96.3% (±0%)
packages/@sanity/cli/src/actions/build/buildVendorDependencies.ts 67.4% (±0%)
packages/@sanity/cli/src/actions/build/checkRequiredDependencies.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/build/checkStudioDependencyVersions.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/build/getViteConfig.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/build/writeSanityRuntime.ts 96.0% (+ 0.8%)
packages/@sanity/cli/src/actions/codemods/reactIconsV3.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/deploy/deployApp.ts 80.5% (±0%)
packages/@sanity/cli/src/actions/dev/devAction.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/dev/devServerRegistry.ts 93.5% (new)
packages/@sanity/cli/src/actions/dev/extractDevServerManifest.ts 20.0% (new)
packages/@sanity/cli/src/actions/dev/getDevServerConfig.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/dev/startAppDevServer.ts 100.0% (+ 13.0%)
packages/@sanity/cli/src/actions/dev/startDevManifestWatcher.ts 90.9% (new)
packages/@sanity/cli/src/actions/dev/startStudioDevServer.ts 100.0% (+ 5.0%)
packages/@sanity/cli/src/actions/dev/startWorkbenchDevServer.ts 100.0% (new)
packages/@sanity/cli/src/actions/dev/writeWorkbenchRuntime.ts 100.0% (new)
packages/@sanity/cli/src/actions/init/bootstrapLocalTemplate.ts 89.7% (±0%)
packages/@sanity/cli/src/actions/init/bootstrapTemplate.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/init/checkNextJsReactCompatibility.ts 0.0% (±0%)
packages/@sanity/cli/src/actions/init/createAppCliConfig.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/createCliConfig.ts 100.0% (+ 50.0%)
packages/@sanity/cli/src/actions/init/createStudioConfig.ts 83.3% (±0%)
packages/@sanity/cli/src/actions/init/initAction.ts 97.2% (+ 0.1%)
packages/@sanity/cli/src/actions/init/initApp.ts 96.0% (±0%)
packages/@sanity/cli/src/actions/init/initError.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/initHelpers.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/initNextJs.ts 88.8% (±0%)
packages/@sanity/cli/src/actions/init/initStudio.ts 87.0% (±0%)
packages/@sanity/cli/src/actions/init/plan/getPlan.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/plan/verifyCoupon.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/plan/verifyPlan.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/project/createProjectFromName.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/project/getOrCreateDataset.ts 97.7% (±0%)
packages/@sanity/cli/src/actions/init/project/getOrCreateProject.ts 95.3% (±0%)
packages/@sanity/cli/src/actions/init/project/getProjectDetails.ts 89.5% (±0%)
packages/@sanity/cli/src/actions/init/project/getProjectOutputPath.ts 60.0% (±0%)
packages/@sanity/cli/src/actions/init/project/promptForAppTemplateSetup.ts 95.2% (±0%)
packages/@sanity/cli/src/actions/init/project/promptForProjectCreation.ts 44.4% (±0%)
packages/@sanity/cli/src/actions/init/project/promptUserForNewOrganization.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/project/promptUserForOrganization.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/scaffoldTemplate.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/init/types.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/manifest/extractCoreAppManifest.ts 93.1% (new)
packages/@sanity/cli/src/actions/manifest/extractManifest.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/manifest/types.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/manifest/writeManifestFile.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/versions/buildPackageArray.ts 100.0% (±0%)
packages/@sanity/cli/src/actions/versions/findSanityModulesVersions.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/copy.ts 94.5% (±0%)
packages/@sanity/cli/src/commands/dev.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/init.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/manifest/extract.ts 100.0% (±0%)
packages/@sanity/cli/src/constants.ts 100.0% (new)
packages/@sanity/cli/src/prompts/init/federation.ts 100.0% (new)
packages/@sanity/cli/src/server/devServer.ts 94.1% (±0%)
packages/@sanity/cli/src/services/datasets.ts 98.8% (±0%)
packages/@sanity/cli/src/services/userApplications.ts 92.8% (±0%)
packages/@sanity/cli/src/telemetry/init.telemetry.ts 100.0% (±0%)
packages/@sanity/cli/src/util/compareDependencyVersions.ts 100.0% (±0%)
packages/@sanity/cli/src/util/packageManager/installationInfo/analyzeIssues.ts 90.0% (±0%)
packages/@sanity/cli/src/util/packageManager/packageManagerChoice.ts 42.9% (±0%)
packages/@sanity/cli/src/util/packageManager/preferredPm.ts 93.0% (±0%)

Comparing 69 changed files against main @ 698f05e7ec78ef3021cd49f98026af03341c859d

Overall Coverage

Metric Coverage
Statements 84.4% (+ 0.3%)
Branches 74.4% (+ 0.4%)
Functions 84.4% (+ 0.4%)
Lines 84.9% (+ 0.3%)

@gu-stav gu-stav merged commit c5f0a95 into feat/workbench Apr 28, 2026
51 of 52 checks passed
@gu-stav gu-stav deleted the fix/workbench-cli-cache branch April 28, 2026 14:55
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