From 39a2735809ba138fb24cc580d2eda8a1754bfb80 Mon Sep 17 00:00:00 2001 From: Vadim Date: Tue, 1 Dec 2026 10:23:34 +0000 Subject: [PATCH 01/11] Extract EmailFrame from the preview so other screens can show email HTML The sandboxed iframe (sandbox="", no referrer, srcdoc) moves into its own component. The preview keeps its height; the frame's border and white background move with it. --- src/editor/Main/Main.css | 6 ----- src/editor/Main/Preview/EmailFrame.css | 8 ++++++ src/editor/Main/Preview/EmailFrame.test.tsx | 14 ++++++++++ src/editor/Main/Preview/EmailFrame.tsx | 30 +++++++++++++++++++++ src/editor/Main/Preview/Preview.tsx | 19 +++---------- 5 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 src/editor/Main/Preview/EmailFrame.css create mode 100644 src/editor/Main/Preview/EmailFrame.test.tsx create mode 100644 src/editor/Main/Preview/EmailFrame.tsx diff --git a/src/editor/Main/Main.css b/src/editor/Main/Main.css index b5bb69c..2634f1f 100644 --- a/src/editor/Main/Main.css +++ b/src/editor/Main/Main.css @@ -51,15 +51,9 @@ } .preview-frame { - display: block; - width: 100%; /* Leaves the manual-editing headers peeking out below. */ height: calc(100vh - 160px - var(--app-header-height, 0px)); min-height: 480px; - border: 1px solid var(--ant-color-border-secondary, #f0f0f0); - border-radius: 8px; - /* The email itself stays white in the dark theme, as mail clients show it. */ - background: #fff; } @media (max-width: 960px) { diff --git a/src/editor/Main/Preview/EmailFrame.css b/src/editor/Main/Preview/EmailFrame.css new file mode 100644 index 0000000..4415cb8 --- /dev/null +++ b/src/editor/Main/Preview/EmailFrame.css @@ -0,0 +1,8 @@ +.email-frame { + display: block; + width: 100%; + border: 1px solid var(--ant-color-border-secondary, #f0f0f0); + border-radius: 8px; + /* The email itself stays white in the dark theme, as mail clients show it. */ + background: #fff; +} diff --git a/src/editor/Main/Preview/EmailFrame.test.tsx b/src/editor/Main/Preview/EmailFrame.test.tsx new file mode 100644 index 0000000..b84676d --- /dev/null +++ b/src/editor/Main/Preview/EmailFrame.test.tsx @@ -0,0 +1,14 @@ +import React from "react"; +import { render, screen } from "@testing-library/react"; +import { expect, test } from "vitest"; +import EmailFrame from "./EmailFrame"; + +test("renders the HTML in a fully sandboxed iframe that sends no referrer", () => { + render(); + + const frame = screen.getByTitle("Sent email"); + expect(frame).toHaveAttribute("srcdoc", "

Hi

"); + expect(frame).toHaveAttribute("sandbox", ""); + expect(frame).toHaveAttribute("referrerpolicy", "no-referrer"); + expect(frame).toHaveClass("email-frame", "extra"); +}); diff --git a/src/editor/Main/Preview/EmailFrame.tsx b/src/editor/Main/Preview/EmailFrame.tsx new file mode 100644 index 0000000..16542cf --- /dev/null +++ b/src/editor/Main/Preview/EmailFrame.tsx @@ -0,0 +1,30 @@ +"use client"; + +import React from "react"; +import "./EmailFrame.css"; + +interface EmailFrameProps { + /** The email's HTML. Untrusted: written by users, the AI assistant, or stored with a sent email. */ + html: string; + /** Accessible name of the frame. */ + title?: string; + /** Extra class, e.g. to size the frame for its screen. */ + className?: string; +} + +/** + * Shows email HTML in a fully sandboxed iframe: no scripts, forms, popups or top-level + * navigation, and an opaque origin that cannot read the editor's storage (where the AI API key + * lives). Do not add `allow-scripts` or `allow-same-origin`. + */ +const EmailFrame = ({ html, title = "Email preview", className }: EmailFrameProps) => ( +