Skip to content

Conversation

@adamziel
Copy link
Collaborator

@adamziel adamziel commented Dec 6, 2025

Summary

This PR ensures that importing from GitHub or ZIP files always goes into a temporary Playground, protecting saved sites from accidental overwrite.

  • GitHub import modal: Before showing the import form, checks if the active site is saved. If so, switches to an existing temporary site or creates a new one.
  • ZIP import: When a file is selected while viewing a saved site, stores the file in state, switches to the temporary site, and completes the import via a useEffect once the switch is done.

Test plan

  • Open Playground and save a site with distinctive content
  • Import a ZIP file while the saved site is active
  • Verify the temporary Playground is selected after import
  • Switch back to the saved site and verify it's unchanged
  • Start Playground directly with ?site-slug=<saved-site> (no temporary site exists)
  • Import a ZIP file
  • Verify a new temporary site is created and selected
  • Verify the saved site remains unchanged

Two e2e tests have been added to verify this behavior automatically.

@adamziel adamziel changed the title Always import into temporary Playground, never into saved sites [Website] Target temporary Playground in Import ZIP, Import from GitHub. Don't overwrite a saved site. Dec 6, 2025
Base automatically changed from manage-sites-blueprints to trunk December 15, 2025 14:03
…ites

When importing a ZIP file while viewing a saved site, the import now
goes into a temporary Playground rather than overwriting the saved site.
This protects saved sites from accidental data loss.

The implementation stores the selected file, switches to an existing
temporary site (or creates a new one), then completes the import via
a useEffect once the switch is done.

Two e2e tests verify this behavior:
- Importing while on a saved site switches to temporary site first
- Importing with no temporary site creates one before importing
@adamziel adamziel force-pushed the start-new-playground-before-importing-data branch 3 times, most recently from 018845c to 7381f45 Compare December 16, 2025 09:55
The ZIP import tests were failing because after navigating the WordPress
iframe to a marker page, the test was checking the body content immediately
before navigation completed.

Fixed by:
- Using website.wordpress() instead of the wordpress fixture to get a fresh
  frame locator reference after navigation
- Increasing the timeout to 30 seconds to allow for iframe navigation time
@adamziel adamziel force-pushed the start-new-playground-before-importing-data branch from 7381f45 to f07c316 Compare December 16, 2025 10:18
Replace 180+ lines of manual byte-by-byte ZIP file creation with the existing
encodeZip and collectBytes utilities from @php-wasm/stream-compression. The
test still creates a minimal ZIP with wp-content/index.php containing a marker
string, but now delegates the ZIP format handling to the library code.
The test was using a fragile approach to remove auto-inserted brackets from
CodeMirror's closeBrackets feature - pressing ArrowDown 4 times while holding
Shift. This would fail if the number of auto-inserted characters changed.

Now we select to end of document using Ctrl+Shift+End (or Meta+Shift+ArrowDown
on Mac) which reliably selects any extra content regardless of how much was
auto-inserted.
@adamziel adamziel merged commit 02a0529 into trunk Dec 16, 2025
33 checks passed
@adamziel adamziel deleted the start-new-playground-before-importing-data branch December 16, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants