Skip to content

Commit

Permalink
[Website] Prevent creation of two temporary sites (#1817)
Browse files Browse the repository at this point in the history
## Motivation for the change, related issues

#1731 introduced multiple Playground management. However, visiting a URL
containing a Blueprint sometimes led to a creation of multiple temporary
sites due to a React effect running twice. This PR prevents that error
by delaying the new site creation until the effect settles down. In
particular, we're waiting for the site list to either get loaded or
error out.

## Testing Instructions (or ideally a Blueprint)

Go to
http://localhost:5400/website-server/?plugin=classic-editor&blueprint-url=https%3A%2F%2Fwordpress.org%2Fplugins%2Fwp-json%2Fplugins%2Fv1%2Fplugin%2Fclassic-editor%2Fblueprint.json%3Frev%3D3158978%26lang%3Den_US
and confirm you only got a single temporary site
  • Loading branch information
adamziel authored Sep 28, 2024
1 parent a415c79 commit eaab4a1
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ export function EnsurePlaygroundSiteIsSelected({
return;
}

// Don't create a new temporary site until the site listing settles.
// Otherwise, the status change from "loading" to "loaded" would
// re-run this entire effect, potentially leading to multiple
// sites being created since we couldn't look for duplicates yet.
if (!['loaded', 'error'].includes(siteListingStatus)) {
return;
}

// If the site slug is missing, create a new temporary site.
// Lean on the Query API parameters and the Blueprint API to
// create the new site.
Expand Down

0 comments on commit eaab4a1

Please sign in to comment.