Skip to content

feat(dashboard): live HTML preview in the template editor (#112)#113

Merged
mohamedboukari merged 2 commits into
mainfrom
feat/template-html-preview
Jun 11, 2026
Merged

feat(dashboard): live HTML preview in the template editor (#112)#113
mohamedboukari merged 2 commits into
mainfrom
feat/template-html-preview

Conversation

@mohamedboukari

Copy link
Copy Markdown
Owner

Summary

Adds a live HTML preview to the dashboard template editor (#112). The template create (/dashboard/templates) and edit (/dashboard/templates/:id) pages now render a preview beside the HTML textarea that updates as you type — no save or test send needed. {{variable}} placeholders are filled with sample values so the preview resembles a delivered email; the stored template keeps its raw {{...}} markup (substitution is preview-only).

Reuses the existing sandboxed-iframe machinery (HtmlPreview) rather than introducing anything new. Dashboard-only — no API, schema, or env changes.

Changes

  • html-preview.tsx — new renderPreviewSamples() (pure, exported), LiveHtmlPreview iframe, and LiveHtmlPreviewScript (debounced textarea→srcdoc updater). Extracted a shared PREVIEW_STYLE_BLOCK + PREVIEW_SAMPLE_VALUES dict so the server-rendered first paint is byte-identical to the client live updates (no flash, single source of truth). The static HtmlPreview/HtmlPreviewScript (email/inbound detail) are untouched — the live variant uses a distinct live-html-preview-frame class.
  • templates.tsx / template-detail.tsx — HTML field is now a responsive two-pane grid (lg:grid-cols-2, stacks on mobile): editor left, preview right in a card matching the email-detail preview chrome, plus a muted caption. Edit page seeds the preview from the saved HTML. Built entirely from existing dashboard tokens (no new colors/radii/font sizes).
  • Security: preview stays sandbox="allow-same-origin" (no allow-scripts) — template <script> never executes. Also added safe to the edit-page HTML textarea, closing a pre-existing </textarea> breakout on that field.
  • Docs: docs/templates.md (new "Dashboard HTML Preview" section), docs/dashboard.md (route table), CHANGELOG.md ([Unreleased]).
  • Tests: new test/unit/render-preview-samples.test.ts; strengthened pages-render.test.ts (live preview frame present, saved HTML sample-rendered, sandbox attribute).

Environment

  • OS: macOS 15
  • Bun version: 1.3.10
  • PostgreSQL version: 16 (Neon)
  • Docker: no

Test Plan

  • Tests pass (bun test) — 392 unit/e2e + 100 integration
  • Types check (bunx tsc --noEmit)
  • Linter passes (bun run lint)
  • Formatting passes (bun run format:check)
  • Tested on Docker (docker compose up) — n/a (no infra change)
  • Manually verified the live preview + dark-mode sync in the browser.

Related Issues

Closes #112

The template create and edit pages now render a live preview beside the
HTML editor that updates as you type — no save or test send needed.
{{variable}} placeholders are filled with sample values so the preview
resembles a delivered email; the stored template keeps its raw markup.

Reuses the existing sandboxed-iframe approach (sandbox="allow-same-origin",
no script execution), shared dark-mode style block, and auto-resize. A
shared sample dictionary + style block keep the server-rendered first
paint byte-identical to the client live updates. Also adds `safe` to the
edit-page HTML textarea, closing a pre-existing </textarea> breakout.

Dashboard-only — no API, schema, or env changes.
@mohamedboukari mohamedboukari merged commit d376f41 into main Jun 11, 2026
7 checks passed
@mohamedboukari mohamedboukari deleted the feat/template-html-preview branch June 11, 2026 10:12
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.

Live HTML preview in the template editor (dashboard)

1 participant