Skip to content

MUL-8700: HTML viewer Fit scales a wider document down to fit - #10055

Merged
forrestchang merged 2 commits into
mainfrom
mul-8700-html-fit-scale
Nov 6, 2026
Merged

forrestchang merged 2 commits into
mainfrom
mul-8700-html-fit-scale

Conversation

@forrestchang

@forrestchang forrestchang commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

What

In the attachment viewer, Fit on an HTML file did not fit. It laid the document out at the stage's width and stopped there, so a page built for a wider screen (a wide comparison table, a grid of min-width cards: the kind of report agents produce) ran past the right edge and scrolled sideways. Only Desktop, which lays out at 1440px and scales down, showed the whole page.

Now Fit lays an over-wide document out at its own width and scales it down so the whole width is visible. The caption shows the size and scale, the same as for the device widths. Pages that already fit stay at 100%, exactly as before.

How

  • utils/iframe-width-bridge.ts: a small script appended to the document (like the fragment-nav shim). The iframe is an opaque origin, so the parent cannot read scrollWidth; the script posts {doc, viewport, needed} on load, resize, fonts-ready and ResizeObserver, and on a measure request from the parent. The needed width counts a classic scrollbar's gutter. A document that clips its own overflow (overflow-x: hidden/clip) reports no overflow. The parent validates every message.
  • HtmlViewportFrame / nextFitAttempt make one attempt per document and stage width:
    • An attempt is started only by an overflow measured at the stage's own width.
    • It is settled only by a report measured at the attempt's width. If the document still overflows there, its overflow grows with the viewport (a width: 100% box with padding, or a breakpoint that jumps wider), so Fit falls back to filling the stage, exactly as before this PR.
    • A document wider than 2880px (2× desktop) fills the stage.
    • Leaving Fit forgets the attempt, so device-width layouts never feed Fit. On return, the frame asks the bridge to re-measure, because a frame already at the stage's width gets no resize event. Switching never remounts the iframe, so page state is kept.
  • The bridge is injected once at the stage, so both the viewer and the open-in-new-tab page get it.

Verification

  • Unit tests cover the bridge (reports, clipping, the forced measure), nextFitAttempt, and the component: scale, keep, fail back to fill, new document, cap, device isolation, re-measure on return, and other-window messages ignored. editor/ and attachments/ suites: 1739 passed. tsc clean; lint clean on the changed files.
  • The reviewer's real-component Chromium script, run on a 1000px stage:
Case First commit Now
Fixed 1080px report 1080, 93% 1080, 93%
width:100%; padding:24px 2880, 35% Fills stage, 100% (same as before this PR)
Breakpoint page, Fit → Desktop → Fit 1600, 63% Fills stage, 100%
  • A 1440px stage with a 1600px page, switching Fit → Desktop → Fit (the frame never resizes): back at 1600 / 90% via the re-measure. A tall, wide page also fits.

Closes MUL-8700.

…o fit (MUL-8700)

Fit laid the document out at the stage's width and stopped there, so a
page built for a wider screen (a fixed-width table, a grid of min-width
cards) ran past the right edge and scrolled sideways; only Desktop, which
lays out at 1440 and scales, showed the whole page.

A width bridge appended to the document reports how wide it needs to be
(the iframe is an opaque origin, so the parent cannot read scrollWidth).
When that is wider than the stage, Fit lays the document out at its own
width and scales it down, with the size and scale in the caption like the
device widths. Pages that fit, and pages that clip their own overflow,
stay at 100%. The learned width only grows for the same document, resets
for a new one, and is capped at twice the desktop width.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
multica-docs Ready Ready Preview Nov 6, 2026 9:17am UTC

Request Review

…rgets it off Fit (MUL-8700)

Review on #10055 found two feedback loops in the learned Fit width:

- A document whose overflow grows with its viewport (a width: 100% box
  with padding) overflowed again at every widened width, so Fit chased it
  up to the 2880 cap and scaled the page to 35%.
- Reports measured at a device width fed Fit too: past a desktop
  breakpoint a responsive page reported 1600, and back in Fit it stayed
  at 1600 / 63% instead of its own 100% layout.

Fit now makes one attempt per document and stage width, started only by
an overflow measured at the stage's own width and settled only by a
report at the attempt's width. If the document still overflows there,
widening cannot settle it and Fit fills the stage as before this change.
A document wider than the cap fills the stage too. Leaving Fit forgets
the attempt, and on return the frame asks the bridge for a fresh
measurement, since a frame already at the stage's width gets no resize.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: multica-agent <github@multica.ai>
@forrestchang
forrestchang merged commit 6644bf0 into main Nov 6, 2026
18 checks passed

This branch was successfully deployed

1 active deployment
Preview – multica-docs — 1c5acb43 Deployed Nov 6, 2026 by vercel[bot]
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.

1 participant