Skip to content

parameters.snapshot.subject hangs until test timeout: "element is not visible" #848

Description

@unional

Description

Setting a subject selector through parameters.snapshot on a Storybook story makes the auto snapshot hang until the test times out. With an explicit timeout the underlying error surfaces:

locator.screenshot: Timeout 1983ms exceeded.
Call log:
  - taking element screenshot
  - waiting for fonts to load...
  - fonts loaded
  - attempting scroll into view action
    2 × waiting for element to be stable
      - element is not visible
    - retrying scroll into view action
    ...

Playwright resolves the selector to an element it considers not visible, then retries until the deadline. Without an explicit timeout the test simply burns the full 15s test timeout with no useful message.

Steps to Reproduce

  1. Add a story with a subject selector:
export const SubjectStory: Story = {
  tags: ['snapshot'],
  parameters: { snapshot: { subject: 'button', timeout: 2000 } },
  args: { label: 'P' },
}
  1. Run vitest run.

Expected Behavior

The snapshot captures the element matched by the selector.

Actual Behavior

The test hangs until the timeout with element is not visible. No snapshot is produced.

Environment

  • OS: Linux 6.18.33.2-microsoft-standard-WSL2 x86_64 (WSL2)
  • Node: v22.23.2
  • Package manager: pnpm 11.22.0
  • storybook-addon-vis: 4.2.3
  • vitest-plugin-vis: 5.1.1
  • Storybook: 10.4.2 (@storybook/addon-vitest 10.4.1)
  • Vitest: 4.1.11, browser mode via @vitest/browser-playwright, chromium

Notes

  • Reproduced identically in both testcases/sb-csf-3 (CSF 3) and testcases/sb-csf-next (CSF Next), on plain stories and on story.test() children — so this is not CSF-Next-specific.
  • Omitting timeout turns this into a bare "Test timed out in 15000ms" with no indication that the snapshot subject is at fault. Even once the selector resolution is fixed, failing fast with a clear "subject not visible / not found" message would help.
  • No Storybook testcase currently exercises parameters.snapshot.subject, which is likely why this went unnoticed. Worth adding coverage alongside the fix.
  • Possibly related but distinct (and closed): Subject not honoured when running npx vitest #327, where subject was ignored rather than hanging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsnapshot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions