Skip to content

Phase 5 item #6: screenshot_responsive renders per breakpoint#13

Merged
vicmaster merged 1 commit into
masterfrom
feat/phase5-responsive-reflow
May 16, 2026
Merged

Phase 5 item #6: screenshot_responsive renders per breakpoint#13
vicmaster merged 1 commit into
masterfrom
feat/phase5-responsive-reflow

Conversation

@vicmaster
Copy link
Copy Markdown
Owner

Summary

The viewer side of item #6 was already true reflow: on breakpoint toggle, JS sets the iframe src to /canvas/:id/html?w=...&h=... and the server route at viewer.ts:75-88 re-renders the HTML with the new dimensions. screenshot_responsive was the half still doing the iframe-resize equivalent: HTML was rendered once at the largest breakpoint and puppeteer just retargeted its viewport per shot. The viewport change alone let @media rules fire (PR #6's responsive: "stack" worked end-to-end), but the body scaffold stayed sized for the largest breakpoint — body.max-width = 1440 and body.min-height = 1024 even on the 390-wide mobile shot.

This change makes screenshot_responsive render per breakpoint so the scaffold matches each viewport.

What lands

  • src/screenshot.tstakeResponsiveScreenshots now takes (bp) => string instead of a pre-built html: string. The function renders inside the loop, so the body scaffold matches the viewport.
  • src/index.ts — the handler passes (bp) => renderToHtml(resolved, bp.width, bp.height, canvas) instead of computing max(breakpoints) and rendering once.
  • test-responsive-reflow.ts — exercises the same closure shape the handler uses. For each preset breakpoint (mobile/tablet/desktop) asserts body.max-width, body.min-height, runtime body.width, and the row flex direction (column when responsive: "stack" fires, row otherwise). 12/12 pass.
  • VISION.md — item Phase 5: responsive hint API + renderer mapping (items #1+#2) #6 ticked.

Found in passing (separable, not fixing here)

At exactly 768px the responsive: "stack" rule fires because the rule is @media (max-width: 768px)max-width is inclusive in CSS. That matches Bootstrap/Tailwind convention (768 is the start of the desktop band, so anything ≤ 767 is mobile, ≤ 1023 is tablet, etc.), but the labelled tablet preset at exactly 768 lands in the mobile rule. If we want 768 to be desktop-side, change the renderer's MOBILE_BREAKPOINT to 767 — but that has knock-on effects worth their own PR.

Test plan

Before: HTML rendered once at `max(breakpoints).{width,height}`; puppeteer
just retargeted its viewport for each shot. The viewport change alone
already let @media rules fire (the responsive: "stack" verification from
PR #6 worked) but the body scaffold stayed sized for the largest
breakpoint — body.max-width = 1440 and body.min-height = 1024 on every
shot, even the 390-wide mobile one.

`takeResponsiveScreenshots` now takes a per-breakpoint render callback
instead of a single pre-built HTML string. The handler in src/index.ts
passes a closure that calls `renderToHtml(resolved, bp.width, bp.height, canvas)`
per shot, so the body scaffold matches the viewport for every breakpoint.

The viewer side of item #6 was already true reflow — on breakpoint
toggle, JS sets the iframe src to `/canvas/:id/html?w=...&h=...` and the
server route at viewer.ts:75-88 re-renders. This PR brings the
screenshot side up to the same standard.

`test-responsive-reflow.ts` asserts at each preset breakpoint that the
runtime body box (max-width, min-height, width) matches the viewport and
that the `responsive: "stack"` rule fires when expected — 12/12 pass.
The other five smokes still pass — no regression on PRs #6-12.

Found in passing: at exactly 768px the `responsive: "stack"` rule fires
because the `@media` is `max-width: 768px`. Matches Bootstrap/Tailwind
convention (768 is the start of the desktop band, not the end of mobile)
but the labelled tablet preset of 768 lands in the mobile rule. Worth a
separate PR if we want 768 to be desktop-side; out of scope here.
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