Skip to content

Previews: discard a preview whose build failed, and list the previews that fill the limit - #6083

Open
chubes4 wants to merge 1 commit into
trunkfrom
fix/discard-failed-previews
Open

chubes4 wants to merge 1 commit into
trunkfrom
fix/discard-failed-previews

Conversation

@chubes4

@chubes4 chubes4 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude, at Chris Huber's direction, traced the count against the list against WordPress.com's /wow-funnel/pending and the backup import logs, then implemented and tested the change.

Proposed Changes

Studio takes the preview count and the limit from WordPress.com, but builds the list it shows from the previews saved for the local site. Two gaps let them drift apart:

  • A failed build was left on WordPress.com. When the archive import failed, createPreview threw and stopped. Nothing discarded the funnel site, so it stayed pending and counted toward the limit until it expired, but Studio had never saved it. Now Studio discards the site on an import failure, then reports the error. A timeout still keeps the site, since its import may still finish. If the discard itself fails, the user still sees the import error.
  • The share panel only listed this site's previews. Previews from other sites, and ones with no local site (made on another computer, through MCP, or left by a failed build before this change), counted toward the limit but weren't shown. studio preview list already brings them in from WordPress.com. At the limit, the Share panel now lists them under the limit notice, each with Delete, so the user can make room.

Testing Instructions

  • npx vitest run packages/providers/wpcom/sites/tests/previews.test.ts apps/ui/src/features/sharing.
    • A failed import discards the site.
    • A failed discard still reports the import error.
    • A timeout keeps the site.
    • At the limit, other previews are listed and can be deleted.
    • Below the limit, they aren't listed.
  • Manually:
    1. Use an account at its limit, with a preview made elsewhere or for another site.
    2. Open Share for a site.
    3. Check that the other previews are listed under "You've used all 10 preview sites…".
    4. Delete one, and check that "Create another preview" becomes available.

Pre-merge Checklist

  • ESLint, Prettier and tsc for apps/ui and packages/providers are clean.
  • Sharing and providers tests pass (194). Both new behaviors' tests fail without the change.

chubes4 added a commit that referenced this pull request Nov 19, 2026
…hat WordPress.com reports (#6084)

## Related issues

- Related to #5980 and #6083. Follows wpcom #262449, which makes
WordPress.com report each preview's `title` and `origin_id`.

## How AI was used in this PR

Claude, at Chris Huber's direction, traced which preview details only
Studio's saved records still knew. It then wrote the WordPress.com
change that reports them, and this change, which uses them.

## Proposed Changes

WordPress.com already decides which previews exist, their address, share
link, expiry, linked live site, count and limit. Studio re-syncs its
saved previews with `/wow-funnel/pending` on every list. Two things only
Studio's saved record still knew:

- **The local site the preview belongs to.** A preview whose record went
missing was listed with no local site. That includes ones whose first
build failed, and ones from before a reinstall. In the Share panel it
only counted toward the limit and was never shown.
- **Its name.** A preview made elsewhere showed only its address.

Studio already sends both when it creates a preview, as `origin_id` and
`blog_title`. With wpcom #262449, `/wow-funnel/pending` returns them.
`origin_id` goes only to the app that created the preview.

- **Provider:** `previews.list()` passes on `title` and `originId`.
- **`reconcilePreviews()`:** a preview with no local site here is put
back with the local site WordPress.com names, if that site is on this
computer. A preview Studio hasn't saved takes its name from its title.
Saved previews keep their local site and name, because renaming a
preview is local.

This removes the last reason the saved records are needed to show a
site's previews. What Studio still stores locally is its own sync state
(`versionId`, `syncedAt`), as it does for any connected site.

Until #262449 deploys, the fields are absent and nothing changes.

## Testing Instructions

- `npx vitest run packages/providers/wpcom/sites/tests/previews.test.ts
apps/cli/lib/tests/snapshots.test.ts`. The 2 new tests fail without the
change:
- The list passes on `title` and `originId`, and leaves out empty ones.
- Reconcile puts an unsaved or unlinked preview back with a local site
that's here. It keeps a saved preview's site, leaves an unknown origin
unlinked, and names unsaved previews from their title.
- After wpcom #262449 deploys:
  1. Remove a preview from `~/.studio/cli.json` `snapshots`.
  2. Run `studio preview list --path <site>`.
3. Check that the preview is listed under its site again, with its name.

## Pre-merge Checklist

- [x] ESLint and Prettier are clean. `tsc` for `packages/providers` is
clean, and `apps/cli` has no new errors.
- [x] Providers and CLI tests pass (`packages/providers`,
`apps/cli/lib`, `apps/cli/commands/preview`). One timing test,
`run-wp-cli-command`, failed in the full run and passed on its own.
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.

1 participant