Skip to content

Studio: Refactor studio preview create to adjust new site logic#2148

Merged
fredrikekelund merged 5 commits intotrunkfrom
stu-991-studio-refactor-studio-preview-create-to-adjust-new-site
Dec 1, 2025
Merged

Studio: Refactor studio preview create to adjust new site logic#2148
fredrikekelund merged 5 commits intotrunkfrom
stu-991-studio-refactor-studio-preview-create-to-adjust-new-site

Conversation

@bcotrim
Copy link
Contributor

@bcotrim bcotrim commented Nov 27, 2025

Related issues

Proposed Changes

  • studio preview create now requires the target folder to be an existing Studio site, failing with a helpful error if not
  • Removed newSites concept from app and cli entirely

Testing Instructions

  • npm start
  • Create a Studio site and remove it without deleting files
  • Close Studio
  • node dist/cli/main.js preview --path <new site folder>
  • Verify it fails.
  • Verify studio preview create <existing-site-folder> works correctly for existing Studio sites

Pre-merge Checklist

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

@bcotrim bcotrim self-assigned this Nov 27, 2025
@bcotrim bcotrim requested review from a team and fredrikekelund November 27, 2025 18:22
@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

📊 Performance Test Results

Comparing 72ea508 vs trunk

site-editor

Metric trunk 72ea508 Diff Change
load 9347.00 ms 11657.00 ms +2310.00 ms 🔴 24.7%

site-startup

Metric trunk 72ea508 Diff Change
siteCreation 16049.00 ms 14082.00 ms -1967.00 ms 🟢 -12.3%
siteStartup 7041.00 ms 6972.00 ms -69.00 ms 🟢 -1.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

Copy link
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

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

Such a relief to clean this upp! I left a couple of comments. The most substantial one relates to the user-data-updated event listener in src/hooks/use-site-details.tsx.

@@ -21,6 +21,7 @@ export async function runCommand( siteFolder: string ): Promise< void > {
try {
logger.reportStart( LoggerAction.VALIDATE, __( 'Validating…' ) );
validateSiteFolder( siteFolder );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
validateSiteFolder( siteFolder );

I think this can be removed. No need to validate the directory type when creating a site if we also use getSiteByFolder to ensure the current directory is added to Studio.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the validateSiteFolder mocking from here, too.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove the validateSiteFolder call in runCommand here as well and replace it with a getSiteByFolder call.

Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here about removing the validateSiteFolder mocking.

@@ -427,7 +426,7 @@ export function SiteDetailsProvider( { children }: SiteDetailsProviderProps ) {

useEffect( () => {
const unsubscribe = window.ipcListener.subscribe( 'user-data-updated', async ( _, payload ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we remove this event listener altogether now..? This might be a useful starting point for picking up latestCliPid changes, but all the logic around addingSiteIds seems to ultimately relate to newSites, which makes me think that we could clean up this file further.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is related to the add site workflow from Studio, not the newSites workflow.
Since we will need to revist this code when we work on having Studio depending on Studio CLI for site management, I suggest adjusting this file at that time.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

This was originally implemented by you in #1272 (d38ad87 in response to #1272 (review)). @ivan-ottinger then updated this listener in #1710 to fix a bug where sites would disappear from the sidebar while being created.

The current logic has no purpose, really. If I attempt to summarize it, this listener will:

  1. Trigger any time the appdata file changes
  2. Load the list of sites from appdata, instantiating each of them as SiteServer
  3. Proceed if appdata.sites is truthy (which it always is, because it's an array)
  4. If there's no site currently being added by Studio, return early
  5. If there IS a site currently being added to Studio, recreate the data state by adding the temporary site to the list of sites from appdata

We should remove this.

@bcotrim bcotrim force-pushed the stu-991-studio-refactor-studio-preview-create-to-adjust-new-site branch from 7afdc43 to 14a6e98 Compare November 28, 2025 16:10
@bcotrim bcotrim force-pushed the stu-991-studio-refactor-studio-preview-create-to-adjust-new-site branch from 14a6e98 to a1d9e92 Compare November 28, 2025 16:43
Copy link
Contributor

@fredrikekelund fredrikekelund 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 changes, @bcotrim, this looks good now 👍

I identified two remaining issues: that we were still using validateSiteFolder in the preview list command, and that the user-data-updated should be removed after all. Since I was planning to land this today (while you're AFK), I went ahead and pushed fixes for both of those.

@fredrikekelund fredrikekelund merged commit c535fba into trunk Dec 1, 2025
7 of 9 checks passed
@fredrikekelund fredrikekelund deleted the stu-991-studio-refactor-studio-preview-create-to-adjust-new-site branch December 1, 2025 12:54
Copy link
Member

@sejas sejas left a comment

Choose a reason for hiding this comment

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

I noticed an issue when creating a new site. I created a Linear issue STU-1071, and I'm working on a quick fix.

trunk-hans-on-wordpress-is-running.mp4

Comment on lines -428 to -453
useEffect( () => {
const unsubscribe = window.ipcListener.subscribe( 'user-data-updated', async ( _, payload ) => {
if ( ! fastDeepEqual( payload.newSites, payload.sites ) ) {
const updatedSites = await getIpcApi().getSiteDetails();
setData( ( prevData ) => {
const tempSite = prevData.find( ( site ) => addingSiteIds.includes( site.id ) );

if ( ! tempSite ) {
return updatedSites;
}

const tempSiteExists = updatedSites.some( ( site ) => site.id === tempSite.id );

if ( ! tempSiteExists ) {
return sortSites( [ ...updatedSites, tempSite ] );
}

return updatedSites;
} );
}
} );

return () => {
unsubscribe();
};
}, [ addingSiteIds ] );
Copy link
Member

Choose a reason for hiding this comment

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

I think this listener is necessary. The site creation in Studio app is currently broken without it.

Copy link
Member

Choose a reason for hiding this comment

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

Quickfix PR #2161

Copy link
Contributor

Choose a reason for hiding this comment

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

Follow-up in #2164

sejas added a commit that referenced this pull request Dec 1, 2025
…n flow (#2161)

- Quick fix site creation. Before this PR the site creation got stuck and never updated the UI.
- The issue was introduced in  #2148 
- That's the reason most of e2e tests were failing, and also the Performance CI, as it always failed on trunk.
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.

3 participants