Skip to content

fix(storybook): screenshots cut off in Vitest integration#335

Merged
gregberge merged 2 commits into
mainfrom
fix/vitest-screenshot-cut-off
Jul 7, 2026
Merged

fix(storybook): screenshots cut off in Vitest integration#335
gregberge merged 2 commits into
mainfrom
fix/vitest-screenshot-cut-off

Conversation

@gregberge

Copy link
Copy Markdown
Member

Problem

Screenshots taken with the Storybook Vitest integration are cut off when the story content is taller than the browser viewport.

The story renders inside an <iframe data-vitest="true"> on the host page, and Argos screenshots the iframe's <body>. Anything overflowing the iframe's box is never painted, so the screenshot ends up with a large blank area — it looks "cut".

setViewportSize grows the iframe to fit the content, but:

  • With fitToContent, fullPage is false, so the iframe-growth branch is skipped.
  • Even when it runs, it grows the iframe before argosCSS injects fitToContent's zoom: 2, so the iframe ends up sized to the un-zoomed content and the (now 2×-taller) content overflows.

This PR (step 1 — repro only)

Adds a Repro/TallContent story with tall content, in both fitToContent and non-fitToContent variants, so Argos captures the current (cut) baseline. The fix is pushed in a follow-up commit so the Argos diff demonstrates the screenshots going from cut → complete.

🤖 Generated with Claude Code

Renders content taller than the viewport, both with and without
`fitToContent`. Without the fix, the `fitToContent` variant is cut off
because the iframe is not grown to fit the zoomed content.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
argos-js-sdk-reference Ready Ready Preview, Comment Jul 7, 2026 3:17pm

Request Review

The story renders inside an `<iframe data-vitest="true">` and Argos
screenshots the iframe's `<body>`. Content overflowing the iframe box is
not painted, so screenshots were cut off.

`setViewportSize` grew the iframe before `argosCSS` (which injects
`fitToContent`'s `zoom`) was applied, so it could not account for the
final content size. Re-fit the iframe height in a `beforeScreenshot`
hook, after stabilization has injected `argosCSS`, so the whole content
is painted. Grow-only, to avoid collapsing an intentionally sized viewport.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gregberge gregberge force-pushed the fix/vitest-screenshot-cut-off branch from 2f0e5c4 to a73706f Compare July 7, 2026 15:14
@gregberge gregberge merged commit c959920 into main Jul 7, 2026
68 checks passed
@gregberge gregberge deleted the fix/vitest-screenshot-cut-off branch July 7, 2026 15:18
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