Skip to content

feat(site-editor): Localhost in the drafts list for Blocks v8 sites - #7875

Closed
tlgimenes wants to merge 28 commits into
split/48-v7-local-as-mainfrom
split/49-v8-localhost-item
Closed

tlgimenes wants to merge 28 commits into
split/48-v7-local-as-mainfrom
split/49-v8-localhost-item

Conversation

@tlgimenes

@tlgimenes tlgimenes commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Part of the v8 Studio stack (base: #7796). The last PR of the v8 Fast Preview + Localhost track, on top of #7874. PO decisions of 2026-10-11.

R5: a "Localhost" item in the drafts list for Blocks v8 sites, replacing Advanced → Local. Choosing it switches the editor to the developer's own deco serve. Schema and content come over the content protocol on localhost (not git or storage), and the preview is the app deco serve reports (describe.preview).

The tree of this branch is identical to feat/blocks-v8-hosted (b016492, a normal merge of this branch, no force-push): git diff --stat origin/split/49-v8-localhost-item origin/feat/blocks-v8-hosted is empty, and both trees hash to b3469a0e2.

PO decision (2026-10-11): no site check. Localhost connects to whatever deco serve answers on the endpoint, even one running another site's folder. Studio doesn't encourage that, but no code blocks it (b7e4cf8 removed the check).

What

  • Draft selector (v8 only): a permanent Localhost row above "New draft" (localhost-row.tsx). It is selected while a deco serve connection is stored, and the trigger then reads "Localhost". Choosing any draft clears it, and so does "Stop using Localhost".

  • Choosing it: the endpoint that answered last time is tried first, else localhost:4545. If nothing is running yet, the editor's existing probe backoff (1 s up to 10 s) connects as soon as deco serve starts, and reconnects on its own after a restart.

  • Remembered per user and project: the key is studio:deco-serve-connection:<userId>:<vmcpId>. The old per-project key only existed on this unreleased stack, so nothing is migrated.

  • States, in plain words with one next step each:

    State What the row shows
    Available "Edit the site running on your computer"
    Connecting Spinner and "Connecting…"
    Connected ✓ and "Connected to localhost:4545"
    Not running "Run deco serve in your site's folder", the command with a copy button, and "We'll connect as soon as it starts"
    Chrome blocks access How to allow it
    Something answered that isn't usable Out-of-date deco serve, another protocol version, another program on the port, or an error, each with its next step

    The row's state comes from the editor's own content backend, so the two never disagree.

  • Preview pane: while there is no app to show (still connecting, or deco serve found no app), it shows a guide instead of booting a sandbox or showing the hosted draft.

  • Advanced: v8 has no Local tab; v7 keeps main's tab (fix(site-editor): v7 Advanced → Local behaves as on main #7874). local-url-submit.ts and the v8 Local form are deleted.

Known limits

  • There is no separate "Reconnecting" state. A connected site keeps working through a short restart (3 failed checks, about 7 s). After that the row shows the not-running guide, which already says it reconnects on its own.

Tests

  • localhost-row.test.tsx:
    • localhostStatus maps backend × permission to each state.
    • A render test for each state: available (choosing calls onSelect), connecting, connected (Stop calls onTurnOff), not running (command plus Copy), needs permission, and a problem (out of date).
    • The per-user and per-project storage key.
  • tsc --noEmit for apps/web, oxlint, biome format and knip are clean. 193 test files under sections-editor, thread, main-panel-tabs, hooks, routes, i18n, lib and chat/pills pass, one process per file, including the site-editor copy (jargon) test.
  • Not done: a full BranchPicker render test (it needs releases, members and branches mocked) and the manual run on the local spike (starting and stopping deco serve).

Stack

v8 Fast Preview track: previous: #7874 · next: #7876 (copy the site id; top of the stack)

Review fixes (94691da)

  • The old tunnel on v8: useLocalPreviewUrl returns no tunnel for a v8 project. A tunnel saved earlier no longer replaces the preview or the editor. v7 is unchanged.
  • Choosing Localhost: it connects to the endpoint this user last used for this project, else the default port. Nothing writes the global /site-editor key from here any more.
  • v7 draft selector: the v8-only hooks moved into V8LocalhostRow, so the v7 picker runs none of them.
  • Preview tab: a gate clause that could never be false is gone.
  • New tests: useDecoServeConnection (per user and project, kept endpoint, v7 reads none, nothing written before the session loads), and useLocalPreviewUrl on v7 vs v8.

Fixes after the PO's run (d5ff0e0..f46bfc4, plus 7fabb89 in #7872)

  1. The local preview recovers by itself (d2ae036, f46bfc4). Before, if deco serve answered before the app (vite dev) was listening, or the app restarted, the frame stayed on Chrome's error page until a save or a reload. Now the preview checks the app from the browser with a no-cors HEAD and backoff (1 s up to 5 s while down, every 10 s while up). Until the app answers, it shows a "Waiting for your app" guide: "Your app at localhost:3000 isn't answering yet…" and "The preview loads on its own as soon as your app answers." Then it loads the app. If the app goes away (2 failed checks in a row), the guide comes back, and the frame loads again on its own when the app returns. /site-editor uses the same tab, so it gets this too.
  2. Not-running replaces an old problem (f6f9855). The local probe used to keep its last answer through failed retries, so the row went on showing an old problem after deco serve stopped. Now the latest probe wins: one failed probe replaces an earlier problem straight away. A connected site gets a short grace period. A failed describe poll on a connected site probes again, so a stop is noticed without waiting for a save.
  3. v8 copy and badge colours:
    • On v8, the Preview server field no longer says "Required for Fast Preview" (7fabb89, in feat(site-editor): Blocks v8 sites always use Fast Preview #7872), because v8 has no Fast Preview switch. It says "Your live site's address. Studio shows your drafts on it before you publish." v7 keeps main's text.
    • The header badge "Local server" is no longer red while it connects or waits for deco serve (2496e10). It stays neutral with a pulsing dot, and turns red only when something answered but can't be used: out of date, another program, or an error.
  4. No storage key without both ids (d5ff0e0). useLocalStorage writes its default on every read, so …:<userId>: keys holding null were written before the project id was known. The Localhost connection now uses a scoped store with these rules:
    • It never writes on read.
    • It doesn't read or write at all until both the user and the project are known.
    • Turning Localhost off removes the key.

Tests added:

  • use-local-app-reachable.test.tsx: the backoff and grace rules; it waits, then reports the app up on its own; a new URL starts over.

  • preview-tab.test.tsx: the guide while the app isn't answering or isn't checked yet; the frame once it answers; the guide when it goes away, then the frame when it's back; nothing is checked without Localhost.

  • use-content-backend.test.ts (localServeBackend):

    • Any site's deco serve connects (no site check).
    • A connected site rides out 2 failures and becomes not-running at 3.
    • An error from the server beats an earlier answer.
    • Not-running, then connected again.
  • deco-serve-chip.test.ts: the badge is pending while connecting or waiting, and red only for real problems.

  • use-deco-serve-connection.test.tsx: nothing written before the session loads or without a project id; a read stores nothing; a choice is stored only under :<userId>:<vmcpId>.

  • preview-settings-rows.test.tsx (feat(site-editor): Blocks v8 sites always use Fast Preview #7872): the v8 hint doesn't mention Fast Preview, and v7 keeps it.

  • Every changed test file passes (one process per file). tsc --noEmit for apps/web, oxlint and biome format are clean.

  • The manual run on the spike was not done. The stack plus a test browser peaks at about 2.9 GB, over the 2 GB per-agent memory limit.

  • d7a3e8957: on a v8 site with no sandbox, the editor no longer spins on "Starting your preview" before the first edit. Nothing starts there, and there is no draft until the first edit, so it shows the published site with no spinner, then the draft as before. hostedDraftSession (v8 marker plus the GitHub backend) is the input; v7 and sandbox sessions are unchanged. Tests: preview-display.test.ts (hosted draft: no spinner before an edit, the draft after, v7 unchanged, Localhost/suspended still win) and content-backend.test.ts (hostedDraftSession).

  • 8517d30de: /site-editor and a project's Localhost Preview render ONE empty state, LocalServeEmptyState (local-serve-empty-state.tsx), with the same copy from one place (decoServe.waiting.*): "Waiting for your computer", the same intro, the same two steps, the Site editor guide / deco serve options / Troubleshooting links, and the moving dot. /site-editor no longer has the Preview-tab/--preview paragraph, the older-site note, the Quickstart link, or the separate "Looking for deco serve…" screen. Problem states (out of date, another program, error) and the Chrome-blocked state look the same in both places. The "Look for deco serve on this computer" button stays, in the same spot, only while Chrome still needs a click before it asks for local-network permission. Choosing Localhost in a project already counts as that click. Tests: site-editor-guide.test.tsx checks that both places render the same markup for "nothing answering" and for "another program on the port". preview-tab.test.tsx was updated. origin/feat/blocks-v8-hosted was updated by a normal merge (23410da), and its tree matches split/49 (f81747205).

🤖 Generated with Claude Code

https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig

v8 sites get a permanent "Localhost" row in the draft selector instead of
Advanced → Local. Choosing it switches the editor to the developer's own
`deco serve`: schema and content over the content protocol on localhost,
and the preview from the app it reports.

- Remembered per user and project
  (`studio:deco-serve-connection:<userId>:<vmcpId>`), tried first at the
  last endpoint that answered, else localhost:4545. Nothing running is
  fine: the probe's backoff connects as soon as `deco serve` starts.
- Every state guides: connecting, connected, not running (the command with
  a copy button), Chrome blocking access, another site, update needed.
  The preview pane guides while there is no app to show, instead of
  booting a sandbox.
- Only this site's `deco serve` is used: `describe.site` must equal the
  project's site id, else the public key in `.deco/secrets.pub` must equal
  the committed one; when neither can be compared it asks to update deco
  serve. A mismatch keeps polling, so starting the right folder connects.
- Advanced has no Local tab for v8; v7 keeps main's. `local-url-submit.ts`
  and the v8 Local form are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
@github-actions github-actions Bot added the claude PR authored by a coding agent label Oct 11, 2026
tlgimenes added a commit that referenced this pull request Oct 11, 2026
Brings feat/blocks-v8-hosted up to the top of the stack (#7875). The
stack branches and this one share no history for the split files, so git
sees add/add conflicts; the resolution is split/49's tree as is. That is
exact: split/44's 53d183a has this branch's tree (42a84aa, a68e1ac),
and everything after it on the stack only adds to it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes and others added 15 commits October 11, 2026 14:26
…gnores the tunnel

- v8 ignores a tunnel saved by the v7 Advanced -> Local (preview and editor);
  v7 reads it as on main.
- The committed public key is read per project (the server always reads
  main's), a failed read stays pending and is retried instead of reading as
  "can't tell the site", and a repository with no key is re-read so adding
  one connects on its own. The copy now asks for the site's .deco/secrets.pub
  instead of an update that doesn't exist yet.
- Once connected, describe is re-read every poll, so a deco serve restarted
  in another site's folder on the same port is caught.
- Choosing Localhost goes to the endpoint this user last connected the
  project to (kept per user and project), else the default port; the global
  /site-editor key is only written by /site-editor again.
- The v8-only hooks live in V8LocalhostRow, so a v7 draft selector runs none.
- Drop a dead clause in the Preview tab's Localhost gate.
- Tests: the site check (match, other site, pending/failed key, restart in
  another folder), useDecoServeConnection per user/project, useLocalPreviewUrl
  v7 vs v8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
useLocalStorage writes its default on every read, so the Localhost keys
were stored as "...:<userId>:" before the project id was known (and with
"null" values on every visit). The connection now uses a scoped store
that never writes on read, and neither reads nor writes until both the
user and the project are known. Turning Localhost off removes the key.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
The local probe kept its last answer through failed refetches, so after
deco serve stopped the Localhost row went on saying "This is another
site" (or "update needed") instead of how to start it. The latest probe
now wins: a failed probe replaces an earlier problem at once, a connected
site rides out a short restart (3 failed probes, about 7 s) before saying
it's not running, and a failed describe poll on a connected site
re-probes it so the outage is noticed without a save.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
"Studio can't confirm this is your site" always asked to add
.deco/secrets.pub to the repository, even when the repository has it and
only the folder deco serve runs in doesn't. The site check now waits for
the repository's answer and says which copy is missing: the local folder
(pull the latest changes, or run deco serve from the site's folder), the
repository (add the file to it), or both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
The header badge turned red while Studio was still connecting or waiting
for deco serve to start, though it reconnects on its own. Waiting now
shows a neutral badge with a pulsing dot; red is kept for an answer that
can't be used (another site, out of date, an error).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
deco serve can answer before the app it names is listening (vite dev
still starting), and the app can restart; the preview frame then stayed
on Chrome's error page until a save or a reload. The preview now checks
the app from the browser (a no-cors HEAD, with backoff) and shows a
"Waiting for your app" guide until it answers, then loads it. When the
app goes away (two failed checks) the guide comes back, and the frame
loads again on its own once it answers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
useEffect is banned in this codebase (oxlint ban-use-effect). The app
check keeps the same behaviour (backoff while down, two failed checks
before an app that answered is called gone) as a react-query poll.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
The guide said "you can edit your content in the meantime", but the
Preview tab shows no sections while it waits; it now says where: the
Content tab. The app's address also broke onto its own line (each piece
of the sentence was a flex item); it stays inline as <code>.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
…check)

PO decision: Studio does not check which site the local `deco serve`
belongs to. Removes matchServeSite (describe.site comparison and the
`.deco/secrets.pub` comparison against the repository's key, plus the
extra read of main's describe for it), the "This is another site" and
"Studio can't confirm this is your site" states with their en/pt-BR
copy, their red-badge cases and tests. Reconnect, the not-running guide,
browser permission, the "another program" protocol check and the
Waiting-for-your-app guide stay. Drops the unused fetchAppProbe export.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
…raft

On a Blocks v8 site edited through the hosted Deco CMS nothing boots, and
the draft only exists once the first edit creates it. Fast Preview's "not
ready" therefore meant "no draft yet", and the published site sat under a
spinner forever. A hosted draft session (v8 marker + GitHub backend, see
hostedDraftSession) now shows the published site with no pill until a
draft exists, then the draft as before. v7 and sandbox sessions unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
… black

v8 only (v7's picker is unchanged): gap-1 between the drafts list items and
before Advanced, and the Localhost row/trigger dot is bg-foreground in every
connection state.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
…alhost row; no Local server pill

- ServeConnectState (components/sections-editor/serve-connect-state.tsx):
  the /site-editor guide's look, shared by /site-editor (guide, first look,
  connecting and problem gates) and a project's Preview while Localhost
  waits for deco serve ("Waiting for your computer"), names no app, or
  waits for the app ("Waiting for your app"). Same header, steps and
  copyable command; a "your computer <-> Studio" wire with a dot shuttling
  back and forth while waiting (connection-shuttle keyframes, 1.8s
  ease-in-out alternate; parked mid-wire under prefers-reduced-motion).
- The Localhost row in the draft selector is just the black dot, the name
  and "Connected"; the command, guide, spinner and Turn off moved out
  (picking a draft turns Localhost off; guidance, waiting and problems live
  in the Preview's empty state, with localhostStatus moved to
  sections-editor/localhost-status.ts).
- The "Local server" header pill is gone: the Localhost row says where it
  stands and the empty state carries every failure (out of date, another
  program, version mismatch, error, Chrome blocking). The Read-only badge
  stays as DecoServeReadOnlyBadge (nothing else says saves are off).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
…ocalhost

Both places now render LocalServeEmptyState with the same copy from one
source: "Waiting for your computer", the project's intro, the two steps
("Studio connects on its own" + "Looking for deco serve on …"), the
Site editor guide / deco serve options / Troubleshooting links and the
travelling dot. Dropped from /site-editor: the Preview-tab/--preview
paragraph, the older-site note, the Quickstart link and the separate
"Looking for deco serve…" first-look screen. Problem states (out of
date, another program, error) and Chrome blocking render the same in
both. The "Look for deco serve on this computer" button stays only where
Chrome still needs a click before asking for local-network permission,
inside the same layout (a project's Localhost choice already was it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes and others added 9 commits October 12, 2026 08:15
useDecoServeConnection imports useVirtualMCP from
@/sdk/hooks/use-virtual-mcp (so the field component tests' stub applies);
mock that module here instead of the @/sdk barrel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
…r the app

- The preview waits until the app `deco serve --preview` names answers, so
  the stub now names a small local app that listens.
- A v8 project connects through Localhost in the drafts list (the Local tab
  is v7 only now): the spec seeds where the user last connected it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
V8LocalhostRow only set the deco serve connection, so the popover stayed
open; draft rows go through pick(), which closes it. The choice moves to
chooseLocalhost(serve, onPicked), which closes the menu on every pick
(chosen already or not) and connects only when not connected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
tlgimenes and others added 3 commits October 12, 2026 23:54
After a save on Localhost (and /site-editor) the preview waited for the
frame to reload itself and trusted that reload. A site that reloads on the
file change, before its server re-reads the content, renders the previous
save, so the preview stayed one edit behind. The frame is cross-origin and
the protocol reports no rendered revision, so the editor now confirms the
site's reload with one more, 500 ms after it. At most one extra reload per
save; the editor's own reloads aren't watched, so no loop. Extracted to
serve-content-reload.ts with tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig
@tlgimenes

Copy link
Copy Markdown
Contributor Author

Folded into #7887 (API) / #7888 (web, stacked on #7887). The tree of #7888 equals this stack's top (split/51-v8-per-site). The branch is kept.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WNwbSEePYNcY5YCgqZURig

@tlgimenes tlgimenes closed this Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude PR authored by a coding agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant