Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): drop leftover-canvas CSS zoom (#6374)
Cameron Pak8b4cd883ac47
diff --git a/apps/web/src/features/email-message/primitives/email-message-body.test.ts b/apps/web/src/features/email-message/primitives/email-message-body.test.tsindex e88ed18f89..db71a89d3f 100644--- a/apps/web/src/features/email-message/primitives/email-message-body.test.ts+++ b/apps/web/src/features/email-message/primitives/email-message-body.test.ts@@ -64,6 +64,8 @@ describe('independent email body', () => {try {await Promise.resolve();const host = root.body.host()!;+ expect(host.style.minWidth).toBe('0');+ expect(host.style.width).toBe('100%');expect(host.shadowRoot?.textContent).toContain('Hello Person');root.body.setShowFullHTML(true);await Promise.resolve();diff --git a/apps/web/src/features/email-message/primitives/email-message-body.ts b/apps/web/src/features/email-message/primitives/email-message-body.tsindex 9d68312887..98b0501526 100644--- a/apps/web/src/features/email-message/primitives/email-message-body.ts+++ b/apps/web/src/features/email-message/primitives/email-message-body.ts@@ -52,6 +52,9 @@ export function createEmailMessageBody(const body = prepared();const attachments = props.message.attachments;const host = document.createElement('div');+ // Keep the renderer at pane width so wide designed email scrolls within it.+ host.style.minWidth = '0';+ host.style.width = '100%';const renderer = mountEmailBody(host, body, {theme: renderingContext.theme(),adaptColors: props.isPersonal || !body.hasTable,diff --git a/apps/web/src/features/email-message/views/email-message-body.tsx b/apps/web/src/features/email-message/views/email-message-body.tsxindex fb8a74d6dd..1d0e3478a3 100644--- a/apps/web/src/features/email-message/views/email-message-body.tsx+++ b/apps/web/src/features/email-message/views/email-message-body.tsx@@ -25,7 +25,7 @@ export function EmailMessageBody(props: EmailMessageBodyProps) {}}><div- class="relative"+ class="relative min-w-0 w-full"classList={{isPersonal: props.isPersonal,'line-clamp-3': !props.isBodyExpanded(),diff --git a/packages/email-renderer/README.md b/packages/email-renderer/README.mdindex c9aaa485a9..98e61b307f 100644--- a/packages/email-renderer/README.md+++ b/packages/email-renderer/README.md@@ -8,7 +8,8 @@ There are two entry points:- `@macro-inc/email-renderer`: deterministic HTML/CSS preparation, quote andsignature selection, and serializable output. It runs in Node without DOM APIs.- `@macro-inc/email-renderer/browser`: Shadow DOM mounting, computed color- adaptation, font normalization, width fitting, image visibility, and cleanup.+ adaptation, font normalization, wide-content scrolling, image visibility, and+ cleanup.It requires a browser, but no framework.```ts@@ -50,7 +51,7 @@ not another untrusted input boundary. The browser layer owns one host's shadowtree and all listeners, resize observers, and resource lifetimes it starts.The host can be attached before mounting or inserted later by the framework.Color preparation waits until it is connected and runs once per content update;-resizes and image loads then only refit layout. A microtask handles synchronous+resizes and image loads then only refresh overflow. A microtask handles synchronousinsertion, and ResizeObserver handles later attachment without polling. Colorpreparation does not depend on animation frames being scheduled.@@ -59,8 +60,9 @@ restarts color processing from the original prepared HTML, so toggling themesdoes not accumulate transformations. `setExpanded(false)` hides images and appliesa three-line CSS text clamp inside its containment boundary. Tables and otheratomic layouts may remain taller; this is not a fixed-height preview. Expansion-removes the text clamp and restores width fitting. These toggles preserve content-and resource identity. `dispose` is idempotent, aborts work, disconnects observers,+removes the text clamp, keeps designed email at its native size, and gives any+remaining wide canvas horizontal overflow. These toggles preserve content and+resource identity. `dispose` is idempotent, aborts work, disconnects observers,removes listeners, and empties the shadow tree. Updating a disposedrenderer does nothing. Mount a new instance into a new host.diff --git a/packages/email-renderer/src/browser/email-body-containment-css.ts b/packages/email-renderer/src/browser/email-body-containment-css.tsindex c62c5c0072..e697387826 100644--- a/packages/email-renderer/src/browser/email-body-containment-css.ts+++ b/packages/email-renderer/src/browser/email-body-containment-css.ts@@ -1,9 +1,9 @@/** Shadow-root containment shared with the email rendering snapshot harness.** Images already cap at the pane. Long signature lines wrap instead of- * tripping whole-message zoom. Quote nesting indents left only. GitHub+ * overflowing the pane. Quote nesting indents left only. GitHub* review mail uses one unwrapped `<pre>` line; wrap like Gmail. Leave- * designed tables alone so newsletters can still use the fit-to-width floor.+ * designed tables alone so newsletters stay at native type and scroll.*/export const EMAIL_BODY_CONTAINMENT_CSS = ['img{display: var(--macro-email-img-display, initial); max-width: 100% !important; height: auto !important;}',diff --git a/packages/email-renderer/src/browser/renderer.ts b/packages/email-renderer/src/browser/renderer.tsindex 6e3657a7b1..c0aba84b9b 100644--- a/packages/email-renderer/src/browser/renderer.ts+++ b/packages/email-renderer/src/browser/renderer.ts@@ -1,4 +1,3 @@-import { fitToWidthZoom } from '../core/fit-to-width-zoom';import type { PreparedEmailBody } from '../core/html';import { processEmailColors, type ThemeColorParams } from './colors';import { EMAIL_BODY_CONTAINMENT_CSS } from './email-body-containment-css';@@ -87,17 +86,14 @@ export function mountEmailBody(if (settings.adaptColors) processEmailColors(shadow, settings.theme);colorsPrepared = true;}- content.style.zoom = '';content.style.overflowX = '';content.style.overflow = expanded ? '' : 'hidden';if (!expanded) return;- const fit = fitToWidthZoom({- containerWidth: host.clientWidth,- contentWidth: content.scrollWidth,- });- if (!fit) return;- content.style.zoom = `${fit.zoom}`;- if (fit.overflowsAfterZoom) content.style.overflowX = 'auto';+ // Keep designed email at its native size. Constrained content wraps;+ // any remaining wide canvas scrolls instead of shrinking the letter.+ if (content.scrollWidth - host.clientWidth > 1) {+ content.style.overflowX = 'auto';+ }};applyExpanded = (value) => {expanded = value;diff --git a/packages/email-renderer/src/core/fit-to-width-zoom.test.ts b/packages/email-renderer/src/core/fit-to-width-zoom.test.tsdeleted file mode 100644index 1a1e316a93..0000000000--- a/packages/email-renderer/src/core/fit-to-width-zoom.test.ts+++ /dev/null@@ -1,38 +0,0 @@-import { describe, expect, it } from 'vitest';-import { FIT_TO_WIDTH_ZOOM_FLOOR, fitToWidthZoom } from './fit-to-width-zoom';--describe('fitToWidthZoom', () => {- it('does not zoom when content fits', () => {- expect(- fitToWidthZoom({ containerWidth: 800, contentWidth: 600 })- ).toBeUndefined();- });-- it('does not zoom when sizes are equal', () => {- expect(- fitToWidthZoom({ containerWidth: 800, contentWidth: 800 })- ).toBeUndefined();- });-- it('ignores a zero-width container', () => {- expect(- fitToWidthZoom({ containerWidth: 0, contentWidth: 1200 })- ).toBeUndefined();- });-- it('uses the raw ratio for a mild newsletter overflow', () => {- expect(fitToWidthZoom({ containerWidth: 800, contentWidth: 836 })).toEqual({- zoom: 800 / 836,- overflowsAfterZoom: false,- });- });-- it('floors pathological width instead of shrinking to dust', () => {- const result = fitToWidthZoom({- containerWidth: 800,- contentWidth: 4000,- });- expect(result?.zoom).toBe(FIT_TO_WIDTH_ZOOM_FLOOR);- expect(result?.overflowsAfterZoom).toBe(true);- });-});diff --git a/packages/email-renderer/src/core/fit-to-width-zoom.ts b/packages/email-renderer/src/core/fit-to-width-zoom.tsdeleted file mode 100644index c72b717107..0000000000--- a/packages/email-renderer/src/core/fit-to-width-zoom.ts+++ /dev/null@@ -1,18 +0,0 @@-/** Floor so a leftover wide canvas (newsletter table) can shrink a little- * without collapsing type the way unbounded `pane / content` zoom does. */-export const FIT_TO_WIDTH_ZOOM_FLOOR = 0.7;--export function fitToWidthZoom(args: {- containerWidth: number;- contentWidth: number;-}): { zoom: number; overflowsAfterZoom: boolean } | undefined {- const { containerWidth, contentWidth } = args;- if (containerWidth <= 0 || contentWidth <= containerWidth) {- return undefined;- }- const zoom = Math.max(FIT_TO_WIDTH_ZOOM_FLOOR, containerWidth / contentWidth);- return {- zoom,- overflowsAfterZoom: contentWidth * zoom > containerWidth + 1,- };-}diff --git a/packages/email-renderer/tests/fixtures/wide-table.json b/packages/email-renderer/tests/fixtures/wide-table.jsonindex 48af9d9952..6109d7366e 100644--- a/packages/email-renderer/tests/fixtures/wide-table.json+++ b/packages/email-renderer/tests/fixtures/wide-table.json@@ -1,6 +1,6 @@{"name": "wide-table",- "description": "Fixed-width 836px table. At 360px the viewer should floor zoom at 0.7 and scroll. At 800px it should shrink slightly without hitting the floor.",+ "description": "Fixed-width 836px table. At 360px and 800px the viewer should keep native type and scroll sideways.","container_widths": [360,800diff --git a/packages/email-renderer/tests/rendering.pw.ts b/packages/email-renderer/tests/rendering.pw.tsindex 187e1fdd58..396e296b31 100644--- a/packages/email-renderer/tests/rendering.pw.ts+++ b/packages/email-renderer/tests/rendering.pw.ts@@ -336,7 +336,64 @@ test('shadow isolation, link safety, literal plaintext and quote expansion use pexpect(result.remaining).toBe(0);});-test('resizes wide content, removes stale scaling, hides collapsed images', async ({+test('wraps readable text while reserving horizontal scroll for atomic layouts', async ({+ page,+}) => {+ const metrics = await page.evaluate(() => {+ const { prepareEmailBody, mountEmailBody, themes } = window.emailRenderer;+ const host = document.createElement('div');+ host.style.width = '240px';+ document.body.append(host);+ mountEmailBody(+ host,+ prepareEmailBody(+ {+ html: `<p>${'Readable prose wraps at spaces. '.repeat(20)}</p><pre>${'unbroken-code-token-'.repeat(30)}</pre><blockquote><p>${'Quoted text stays inside the pane. '.repeat(20)}</p></blockquote><div class="macro-email-signature">${'long-signature-token-'.repeat(30)}</div>`,+ },+ { showQuotedContent: true }+ ),+ { theme: themes.light, adaptColors: false, normalizeFonts: false }+ );+ const content = host.shadowRoot?.querySelector('div');+ const prose = content?.querySelector('p');+ const pre = content?.querySelector('pre');+ const signature = content?.querySelector('.macro-email-signature');+ const quote = content?.querySelector('blockquote');+ if (+ !(content instanceof HTMLElement) ||+ !(prose instanceof HTMLElement) ||+ !(pre instanceof HTMLElement) ||+ !(signature instanceof HTMLElement) ||+ !(quote instanceof HTMLElement)+ ) {+ throw new Error('expected readable email elements');+ }+ return {+ hostWidth: host.clientWidth,+ contentWidth: content.scrollWidth,+ proseWidth: prose.scrollWidth,+ preWidth: pre.scrollWidth,+ signatureWidth: signature.scrollWidth,+ quoteWidth: quote.scrollWidth,+ zoom: getComputedStyle(content).zoom,+ overflowX: getComputedStyle(content).overflowX,+ };+ });+ expect(metrics.hostWidth).toBe(240);+ expect(metrics.zoom).toBe('1');+ expect(metrics.overflowX).toBe('visible');+ for (const width of [+ metrics.contentWidth,+ metrics.proseWidth,+ metrics.preWidth,+ metrics.signatureWidth,+ metrics.quoteWidth,+ ]) {+ expect(width).toBeLessThanOrEqual(metrics.hostWidth);+ }+});++test('scrolls wide content at native size and hides collapsed images', async ({page,}) => {await page.evaluate(() => {@@ -355,12 +412,11 @@ test('resizes wide content, removes stale scaling, hides collapsed images', asynhost.addEventListener('collapse', () => renderer.setExpanded(false));});const content = page.locator('#resize-host > div');- await expect(content).toHaveCSS('zoom', '0.7');+ await expect(content).toHaveCSS('zoom', '1');await expect(content).toHaveCSS('overflow-x', 'auto');await page.locator('#resize-host').evaluate((host) => {(host as HTMLElement).style.width = '1200px';});- await expect(content).toHaveCSS('zoom', '1');await expect(content).toHaveCSS('overflow-x', 'visible');await page.locator('#resize-host').dispatchEvent('collapse');await expect(content).toHaveCSS('overflow-x', 'hidden');diff --git a/packages/email-renderer/tests/snapshots/wide-table-dark-360.png b/packages/email-renderer/tests/snapshots/wide-table-dark-360.pngindex e73134630d..8d20212d2a 100644Binary files a/packages/email-renderer/tests/snapshots/wide-table-dark-360.png and b/packages/email-renderer/tests/snapshots/wide-table-dark-360.png differdiff --git a/packages/email-renderer/tests/snapshots/wide-table-dark-800.png b/packages/email-renderer/tests/snapshots/wide-table-dark-800.pngindex a6bfa3dba3..3f63352fc9 100644Binary files a/packages/email-renderer/tests/snapshots/wide-table-dark-800.png and b/packages/email-renderer/tests/snapshots/wide-table-dark-800.png differdiff --git a/packages/email-renderer/tests/snapshots/wide-table-light-360.png b/packages/email-renderer/tests/snapshots/wide-table-light-360.pngindex 97cf4a9cb6..8d20212d2a 100644Binary files a/packages/email-renderer/tests/snapshots/wide-table-light-360.png and b/packages/email-renderer/tests/snapshots/wide-table-light-360.png differdiff --git a/packages/email-renderer/tests/snapshots/wide-table-light-800.png b/packages/email-renderer/tests/snapshots/wide-table-light-800.pngindex a6bfa3dba3..3f63352fc9 100644Binary files a/packages/email-renderer/tests/snapshots/wide-table-light-800.png and b/packages/email-renderer/tests/snapshots/wide-table-light-800.png differ