Skip to content

Commit eaab4a1

Browse files
authored
[Website] Prevent creation of two temporary sites (#1817)
## 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
1 parent a415c79 commit eaab4a1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/playground/website/src/components/ensure-playground-site/ensure-playground-site-is-selected.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export function EnsurePlaygroundSiteIsSelected({
7575
return;
7676
}
7777

78+
// Don't create a new temporary site until the site listing settles.
79+
// Otherwise, the status change from "loading" to "loaded" would
80+
// re-run this entire effect, potentially leading to multiple
81+
// sites being created since we couldn't look for duplicates yet.
82+
if (!['loaded', 'error'].includes(siteListingStatus)) {
83+
return;
84+
}
85+
7886
// If the site slug is missing, create a new temporary site.
7987
// Lean on the Query API parameters and the Blueprint API to
8088
// create the new site.

0 commit comments

Comments
 (0)