Skip to content

feat(preview): implement the host-side live-preview surface - #94

Merged
7shep merged 1 commit into
mainfrom
agent/issue-58-preview-protocol
Jul 31, 2026
Merged

feat(preview): implement the host-side live-preview surface#94
7shep merged 1 commit into
mainfrom
agent/issue-58-preview-protocol

Conversation

@7shep

@7shep 7shep commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the remaining gaps in Preview's live-preview surface: viewport controls, manual reload, and diagnostics that survive a refresh.

  • Viewport controls — a role="group" labelled Preview width with Desktop and Mobile buttons carrying aria-pressed. Mobile constrains the frame to 390px; Desktop releases it. Keyboard-operable, state readable without colour.
  • Manual reloadReload preview remounts the frame by key and immediately re-reads runtime state rather than waiting for the next poll. A broken state gets the same affordance as Retry now, next to the existing route back to Studio.
  • Diagnostics preserved across refreshes — a poll that lands on a state with no diagnostic of its own no longer erases the last explanation. A successful build clears it, so a stale error cannot be carried forward.
  • Reduced motion — already handled by the global prefers-reduced-motion block in styles.css; no change needed. button:focus-visible now gets the same visible outline as links and the frame.

On the message protocol

The issue asks for a typed postMessage protocol with trusted-origin validation. That is deliberately not what this PR builds, and apps/preview/README.md now says so where a future contributor will look.

  • ADR 0001 §9 lists a privileged postMessage bridge as an iframe-escape threat and excludes it from the MVP. The frame stays sandbox="allow-scripts" with no same-origin, navigation, popup, download, or form capability, and receives no message it could act on.
  • The typed protocol the issue wants already exists, in the right place: project identity, build state, readiness, failure, and preview URL travel over @universal/runtime-contracts from the trusted runtime. RuntimePreviewClient validates every response before any state change, rejects a descriptor whose project/build/revision does not match the runtime's own record as stale, and rejects a non-loopback preview origin. Those paths are covered in preview-client.test.ts.
  • Viewport and reload are therefore host-side operations — resize and remount from outside — which need no cooperation from untrusted code.

Reversing that boundary should be an ADR amendment, not a component change. Happy to open one if you'd rather have the channel.

Validation

  • pnpm --filter @universal/preview test — 20 passing, including the new viewport, reload, retention, and in-place-retry coverage
  • pnpm --filter @universal/preview typecheck, lint (clean), build
  • pnpm format:check

Not run: a rendered pass against a live runtime. The new controls only appear in the ready state, which needs a generated build; they are covered by component tests instead. Worth a rendered check before merge if you have a runtime handy.

Stacking

Based on agent/issue-53-preview-tests (#91), which adds the Vitest setup these tests need. Merge that first; this diff is only the app change plus its tests and README section.

Closes #58.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
universal Skipped Skipped Jul 31, 2026 6:41pm

…etention

Preview could embed a build but not resize it, reload it on demand, or keep
the last diagnostic visible when a later poll reported nothing.

Add host-side desktop and mobile widths, a manual reload that remounts the
frame and re-reads runtime state, and sticky diagnostics that a successful
build clears. The sandboxed frame gains no new capability.

Closes #58.

Co-Authored-By: Claude <noreply@anthropic.com>
@7shep
7shep force-pushed the agent/issue-58-preview-protocol branch from 9b5d218 to a63f798 Compare July 31, 2026 18:41
@7shep
7shep changed the base branch from agent/issue-53-preview-tests to main July 31, 2026 18:41
@7shep
7shep merged commit 46c420f into main Jul 31, 2026
7 of 12 checks passed
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.

feat(preview): implement a typed, sandboxed live-preview protocol

1 participant