Skip to content

Update desktop app site state when making CLI changes#2799

Open
nb wants to merge 2 commits intotrunkfrom
fix/cli-site-sync
Open

Update desktop app site state when making CLI changes#2799
nb wants to merge 2 commits intotrunkfrom
fix/cli-site-sync

Conversation

@nb
Copy link
Member

@nb nb commented Mar 13, 2026

Reproduce

  • Start from a stopped site
  • Open the desktop app
  • studio site start --path ~/Studio/<existing-site>
  • Site starts successfully
  • The desktop app doesn't indicate the site is running

How AI was used in this PR

Used Codex to trace the CLI-to-app event flow, identify the missing registration path for externally started sites, and draft the initial code and test changes. I reviewed the final implementation, adjusted the test coverage, and ran the verification commands locally.

Proposed Changes

  • Register missing sites when the desktop app receives site-updated events from the CLI event subscriber, not only on site-created
  • This allows sites started outside the app UI, including studio ai and studio site start, to appear as running in the app
  • Add a regression test covering an externally started site flowing through the CLI event subscriber
  • Make development startup more robust by treating DevTools service worker startup failures as non-fatal, as I hit this issue
  • Add a test covering the dev-only startup fallback path

Testing Instructions

  • Start the Studio dev app:
    • npm start
  • In a second terminal, build and run the local CLI:
    • npm run cli:build
    • node apps/cli/dist/cli/main.js site start --path ~/Studio/<existing-site>
  • Confirm the started site appears as running in the dev app
  • Run verification:
    • npx eslint --fix apps/studio/src/index.ts apps/studio/src/tests/index.test.ts apps/studio/src/modules/cli/lib/cli-events-subscriber.ts apps/studio/src/modules/cli/lib/tests/cli-events-subscriber.test.ts
    • npm test -- apps/studio/src/tests/index.test.ts apps/studio/src/modules/cli/lib/tests/cli-events-subscriber.test.ts
    • npm run typecheck

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@nb nb added the Bug label Mar 13, 2026
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Mar 13, 2026

📊 Performance Test Results

Comparing 3f3345f vs trunk

app-size

Metric trunk 3f3345f Diff Change
App Size (Mac) 1278.61 MB 1278.61 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 3f3345f Diff Change
load 1847 ms 1863 ms +16 ms ⚪ 0.0%

site-startup

Metric trunk 3f3345f Diff Change
siteCreation 6110 ms 6082 ms 28 ms ⚪ 0.0%
siteStartup 3936 ms 3940 ms +4 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@nb nb requested a review from bcotrim March 13, 2026 15:47
Copy link
Contributor

@bcotrim bcotrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change @nb
I tried, but couldn't replicate the start issue trunk — tested starting a site via CLI both with Studio open and before opening Studio, and both cases showed the correct running state.
Could you share more detailed steps/logs?

The setupDevelopmentExtensions looks great!

@nb
Copy link
Member Author

nb commented Mar 13, 2026

@bcotrim you're right, I was testing with 1.7.5 where it was broken, but it does to work with trunk! Looking back at my diff, I actually didn't change the logic :) It's a bit cleaner now and given the extra test, I'd still suggest merging it. Sorry for the hassle.

nb added 2 commits March 14, 2026 00:26
Sites started outside the desktop app are announced through the CLI\nevents stream as site-updated events. The subscriber only registered\nmissing sites on site-created, so a site started via studio ai or\nstudio site start could be dropped before the renderer ever saw it.\n\nRegister missing sites on updated events too and cover the path with a\nsubscriber regression test.
Electron can fail to start the React and Redux DevTools service worker\nwhen Studio boots in development. That rejection was unhandled, which\nmade npm start noisy even though the app could continue to run.\n\nWrap development extension setup in a guard, log a warning, and keep\nbooting when the worker fails to start.
@nb nb force-pushed the fix/cli-site-sync branch from dba9274 to 3f3345f Compare March 13, 2026 23:26
@bcotrim
Copy link
Contributor

bcotrim commented Mar 16, 2026

@bcotrim you're right, I was testing with 1.7.5 where it was broken, but it does to work with trunk! Looking back at my diff, I actually didn't change the logic :) It's a bit cleaner now and given the extra test, I'd still suggest merging it. Sorry for the hassle.

Unless I am missing something it does change the behavior, from creating sites on Studio app only on CREATED events, to creating sites on Studio app for any received event.
The current condition was introduced to prevent some issues, like duplicated sites, here: #2415
Since we can’t replicate the original issue anymore, I’d suggest keeping the current behavior unchanged.
Adding the tests and the development startup are still good improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants