Repository navigation
feat(sandbox): show production site while the preview dev server wakes - #5084
Merged
Merged
Conversation
guitavano
force-pushed
the
guitavano/sandbox-prod-preview-fallback
branch
from
July 23, 2026 03:21
417e697 to
e59e0be
Compare
Lovable-style boot for deco.cx projects: while the sandbox dev server is
still waking, paint the linked site's live production URL in the preview
iframe with a non-blocking "waking" pill, instead of the full blocking
overlay. The user sees their site and can open Blocks immediately; the
iframe swaps to the sandbox preview once the dev server is up.
- Production URL is derived (no migration) from the agent's
`metadata.siteSlug` via the public `{slug}.deco.site` convention.
- New pure, unit-tested `resolvePreviewDisplay` decides the canvas surface
(sandbox / production fallback / blocking overlay); GitHub-only projects
with no siteSlug keep the original blocking-overlay behavior.
- The production frame is view-only: visual/CMS editor injection, path
sync and analytics are skipped for the cross-origin fallback; the Blocks
panel still reads the committed snapshot.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ing it
Don't guess `{siteSlug}.deco.site` — a site's real production URL can be a
custom domain. Persist the actual URL deco.cx reports.
- Add `productionUrl` to the virtual-mcp metadata schema (entity/create/update).
- Populate it at deco.cx import time from the site's production domain (the
value was already fetched to render the import cards), via a new shared
`productionUrlFromDomain` helper.
- Preview reads `metadata.productionUrl` (sanitized to a valid http(s) URL)
instead of deriving from siteSlug. Sites imported before this field exists
simply fall back to the original blocking overlay.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Add a "Production URL" field to the Sandbox card in agent settings, bound to `metadata.productionUrl` (autosaved via the existing form). Normalizes on blur (bare host → https, invalid → null) with the shared `productionUrlFromDomain` helper. This lets users set/change the preview fallback URL — including for projects imported before the field existed, or when a site's custom domain changes — not just at import time. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Repos commonly gitignore `.deco/blocks.gen.json` (a multi-MB single-line
merge of `.deco/blocks/*.json`, regenerated on dev cold-start), so a fresh
sandbox has the block sources but not the merged artifact — the CMS/Blocks
couldn't be read until the dev runtime came up, even with the FS ready.
The daemon's /read handler now regenerates it on the fly when the file is
absent: merge each `.deco/blocks/<stem>.json` into
`{ [decodeURIComponent(stem)]: <contents> }` — exactly what the runtime
emits. Async reads + raw-text concatenation (no per-value JSON.parse/
stringify) keep the single-threaded event loop free. Returned un-numbered:
pretty JSON never matches the `^\d+\t` line-number prefix, so the client's
stripLineNumbers is a no-op and JSON.parse still works — no client change.
Inert when the file exists (normal read wins) or when there's no blocks
dir (falls through to the existing 404).
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Enlarge the preview "starting" pill (bigger padding/text/spinner, stronger contrast) and simplify the copy to just "Starting your preview" — no mention of showing the production site. Renames the i18n key accordingly. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The URL bar / device toggles / Blocks toolbar was gated on `daemonReady`, so during the production-fallback boot window (daemon still provisioning) the canvas showed only the "starting" pill with no topbar. Show the toolbar whenever an iframe surface is visible: the production fallback gets it right away; sandbox mode still waits for the daemon. Page/Blocks controls fill in once the daemon is up (they read the committed snapshot, empty until then). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Give the waking toast an opaque grey (bg-muted) card with border/shadow so it contrasts against both the grey boot canvas and a white production page while it loads, and add a description line clarifying that edits made now will show in the preview once it's ready. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Fresh/Deno deco sites never persist meta.gen.json to the FS (the schema only exists at runtime), so the Blocks panel stayed stuck "loading" until the dev server booted — even though the blocks (decofile) were already readable from the committed .deco/blocks/ sources. Pull the schema from the linked production site's /live/_meta as a last-resort source: production is a live deco runtime serving the same route (and sends `access-control-allow-origin: *`), so the browser can read it directly. Priority is live (dev server) → committed snapshot (branch-accurate) → production, so a committed meta.gen.json still wins; production only fills the gap for sites that don't commit one. Content (decofile) intentionally stays FS/branch-sourced. Reuses the persisted metadata.productionUrl; the ordering is a pure, unit-tested helper. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Clarify that metadata.productionUrl ideally isn't set by hand — it's auto-populated at import and should be sourced from the site's `domains` array once the domain-setup capability lands. Co-Authored-By: Claude Opus 4.8 <[email protected]>
guitavano
force-pushed
the
guitavano/sandbox-prod-preview-fallback
branch
from
July 23, 2026 11:56
968b98a to
f98896f
Compare
…light Review remediation: - Blocker: resolvePreviewDisplay now yields the canvas for the `othersThread` state too, so a teammate's-branch confirmation gate no longer leaks the toolbar / production iframe / waking pill behind it (+ test). - Important: single-flight the daemon's blocks.gen.json regeneration so concurrent cold reads on a large shared sandbox share one rebuild instead of piling ~11MB serialization bursts on the event loop (health-probe safety) (+ test). - Tighten the daemon comment: the merge avoids per-value JSON work, but the response's full-payload stringify is downstream (no worse than the committed read path). - Extract pickProductionDomain helper (dedup the import-dialog domain pick) (+ test). - Document why useDecofile has no production fallback (content stays branch-accurate; schema in useLiveMeta can't). - Add the missing metaSourceOrder "live + no production" case. Co-Authored-By: Claude Opus 4.8 <[email protected]>
decocms Bot
pushed a commit
that referenced
this pull request
Jul 23, 2026
PR: #5084 feat(sandbox): show production site while the preview dev server wakes Bump type: minor - decocms (apps/mesh/package.json): 4.105.0 -> 4.106.0 - @decocms/mesh-sdk (packages/mesh-sdk/package.json): 1.31.0 -> 1.32.0 - @decocms/sandbox (packages/sandbox/package.json): 1.19.0 -> 1.20.0 - deploy/helm/sandbox-env (chart 0.9.12) (deploy/helm/sandbox-env/values.yaml deploy/helm/sandbox-env/Chart.yaml): image.tag/appVersion -> 1.20.0 Deploy-Scope: both
rafavalls
added a commit
that referenced
this pull request
Jul 23, 2026
Only conflict was apps/mesh/src/web/components/sandbox/preview/preview.tsx, where main's new preview "display model" (#5084 production fallback while the dev server wakes, #5089 resilient path-param picker, #5086 confirm-before- auto-start) collided with this branch's header-portal redesign of the same toolbar. Resolution: keep the redesign's structure (urlControls / moreMenu extracted and portaled into the panel header via headerSlot) and adopt main's display model: - showPreviewToolbar now follows main's visibility — shown once an iframe surface is active (sandbox when the daemon is up, or the production fallback while it wakes) instead of `daemonReady && previewState.kind === "iframe"`. - canVisualEdit uses `display.mode === "sandbox"`. - "Open in new tab" resolves the URL via `iframeSrc ?? display.iframeBase` (previewState.previewUrl no longer exists under the display model). Main's toolbar-internal changes were pure re-indentation (verified against the base diff), so the extracted urlControls/moreMenu already carry them; main's other features (waking pill, confirm dialog) live outside the toolbar and auto-merged. Verified: tsc across all workspaces, oxlint (0), knip (clean), format.
guitavano
added a commit
that referenced
this pull request
Aug 4, 2026
…en absent (#5687) * feat(sandbox): regenerate blocks.gen.json in the Go daemon's /read when absent `.deco/blocks.gen.json` is the runtime's merge of every `.deco/blocks/*.json`; most repos gitignore it (a multi-MB single line that conflicts on every content PR and is regenerated on dev cold-start), so a fresh sandbox has the block sources but not the merged artifact. The web CMS reads it via the daemon's /read proxy (readCommittedJson -> use-decofile) so the Blocks UI is editable before the dev server boots. The TypeScript daemon synthesized this merge on the fly in /read (added in #5084) but the behavior was dropped when that daemon was deleted (#5575) and never ported to Go — so on main today /read 400s and the CMS shows "decofile unavailable" until the dev server is up. Restore it in Go: - decofile.GenerateFromBlocks / GenerateFromBlocksDeduped: deterministic, byte-spliced merge keyed by the decode-until-stable filename stem (fixes the double-encoded-stem bug the old decode-once path had), single-flight coalesced so concurrent cold reads share one multi-MB build. - fs.Read falls back to the merge only when the absent path's basename is blocks.gen.json; every other absent file still 400s. - Go unit tests for the merge + a black-box daemon-e2e spec. Co-Authored-By: Claude Opus 4.8 <[email protected]> * review: harden the decofile /read fallback Addresses a multi-perspective review of the fallback: - security: gate the fallback on a relative path. An absolute body.Path bypasses SafePath, so allowing it would turn the merge into an arbitrary sibling-blocks/ directory glob; the CMS only ever sends relative paths. Proven by a routes unit test that points an absolute path at the real repo's gen artifact and asserts it still 400s while the relative form merges. - robustness: defer the singleflight cleanup so a panic in the merge can't leave a stale in-flight entry that wedges every future reader of that dir. - testing: cover the riskiest path — pretty-printed multi-line blocks round- tripping through the consumer's stripLineNumbers (inlined in the e2e, unit- asserted no merged line starts with a line-number prefix) — plus a concurrent -race test for the coalescer. - cleanup: unexport generateFromBlocks (only the deduped wrapper calls it), splice via bytes.TrimSpace to drop a per-block string copy, and broaden the package doc to cover generation alongside validation. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lovable-style boot for projects linked to a live site. While the sandbox dev server is still waking, the preview canvas paints the linked site's live production URL inside the iframe with a non-blocking "waking" pill, instead of the full blocking booting overlay. The user sees their site immediately and can open Blocks / edit the CMS right away; the iframe swaps to the sandbox preview the moment the dev server is up.
Product decisions (confirmed with @guitavano)
{siteSlug}.deco.site— a site's real production URL can be a custom domain. The actual URL deco.cx reports is stored on the agent'smetadata.productionUrl.metadata(branch-independent), alongsidesiteSlug/githubRepo. No DB migration (metadata is JSON).What changed
productionUrladded to the virtual-mcp metadata (entity / create / update) inpackages/mesh-sdk.shared/deco-site-production-url.ts):productionUrlFromDomain(bare host →https://…, validated) andsanitizeProductionUrl(validate stored value to a canonical http(s) href — rejectsjavascript:/garbage).import-from-deco-dialog.tsxcomputes the production URL from the site's domains (d.productionfirst, else the first domain) and persists it on create.ProductionUrlFieldin the settings Sandbox card, bound tometadata.productionUrl, autosaved via the existing form; normalizes on blur.metadata.productionUrl(sanitized) — no siteSlug derivation. New pure, unit-testedresolvePreviewDisplaydecides the canvas surface:sandboxiframe,productionfallback + waking pill, or (no productionUrl) today's blocking overlay. Gated onprogress.status(boot no longer in progress), so a failed boot correctly shows the sandbox crash page, not a false "waking" pill.vm_preview_loadedanalytics are skipped for the cross-origin fallback (injection already targets the sandbox origin, so it's a no-op there anyway). The Blocks panel keeps working from the committed.deco/*.gen.jsonsnapshot.previewSurfaceActive(the deferred follow-up from feat: Genesis #1) so Blocks is reachable during the production fallback. iframekeytracks the base URL so it remounts cleanly on the production→sandbox swap.Behavior when there's no
productionUrlGitHub-only projects, or sites imported before this field existed and never set →
productionUrlisnull→ exact current behavior (blockingSandboxStateCarduntil the dev server is ready). Suspended/errored states are untouched.Testing
bun test shared/deco-site-production-url.test.ts— URL normalization/validation (bare host, existing scheme, whitespace,javascript:/garbage/empty/nullish).bun test .../preview-display.test.ts— every display-mode branch (running → sandbox; failed → sandbox crash page, no pill; fresh/warming boot → production + pill; no productionUrl → blocking overlay; suspended/errored passthrough).bun run checkclean;bun run lint0 errors on changed files;bun run fmtapplied.🤖 Generated with Claude Code
Also in this PR: daemon regenerates
blocks.gen.jsonwhen absentRelated, but independent of the production-preview fallback above — both make the editing surface usable earlier in the boot.
Problem: Many repos gitignore
.deco/blocks.gen.json(a multi-MB single-line merge of.deco/blocks/*.json, regenerated on dev cold-start — see casaevideo-tanstack). So a fresh sandbox has the block sources but not the merged artifact, and the CMS/Blocks panel (which reads the committed snapshot via the daemon when the dev server is down) couldn't render until the runtime came up — even with the FS ready.Fix: The daemon's
/readhandler regenerates it on the fly when absent — merging each.deco/blocks/<stem>.jsoninto{ [decodeURIComponent(stem)]: <contents> }, exactly what the runtime emits (the stem is theencodeURIComponentof the block id).readdir/readFile+ raw-text concatenation — no per-valueJSON.parse/JSON.stringifyof the multi-MB payload; only the small keys are JSON-encoded.^\d+\tline-number prefix, so the existingstripLineNumbersis a no-op andreadCommittedJson'sJSON.parseworks as-is.blocksdir it falls through to the existing 404. A malformed block isn't caught here (parsing would block the loop) — the clientJSON.parsefails → 'no snapshot', same as today; write/edit handlers already gate block validity.Tests: 7 new cases in
routes/fs.test.ts(decoded-key merge incl.%2F→/; no-dir / empty-dir → null; ignores non-json + empty files; on-the-fly generation via the handler; committed file preferred; still-404 with no blocks dir). Fullbun run checkclean.