Skip to content

Addon-Vitest: Subscribe for run completion before triggering it - #35291

Merged
Sidnioulz merged 2 commits into
storybookjs:nextfrom
tsushanth:fix/addon-vitest-subscribe-before-trigger
Jun 29, 2026
Merged

Sidnioulz merged 2 commits into
storybookjs:nextfrom
tsushanth:fix/addon-vitest-subscribe-before-trigger

Conversation

@tsushanth

@tsushanth tsushanth commented Jun 26, 2026 •

Copy link
Copy Markdown

Fixes #35289

The TRIGGER_TEST_RUN_REQUEST handler in preset.ts sends TRIGGER_RUN to the store and then subscribes to completion events. If the run finishes quickly — which happens for focused or small story sets via @storybook/addon-mcp — the TEST_RUN_COMPLETED event can fire before the subscription is in place. The response channel never emits TRIGGER_TEST_RUN_RESPONSE, and the MCP caller hangs until it times out.

The fix registers the store.subscribe call before store.send, so any completion event that fires synchronously or near-synchronously is captured. The logic inside the subscriber is unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a timing issue in programmatic test runs where very fast completions could be missed.
    • Improved reliability by ensuring the test-run listener is set up before dispatching the trigger, so completion, error, and cancellation outcomes are captured consistently.

Manual testing

See instructions on #35289. Use canary 0.0.0-pr-35291-sha-a08be029

@coderabbitai

coderabbitai Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread code/addons/vitest/src/preset.ts Outdated
@Sidnioulz Sidnioulz added bug ci:normal Run our default set of CI jobs (choose this for most PRs). verification:failed qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Jun 26, 2026
@Sidnioulz Sidnioulz changed the title addon-vitest: subscribe for run completion before sending TRIGGER_RUN Addon-Vitest: Subscribe for run completion before triggering it Jun 26, 2026
@Sidnioulz Sidnioulz self-assigned this Jun 26, 2026
@storybook-app-bot

Copy link
Copy Markdown
Contributor

Package Benchmarks

Commit: a08be02, ran on 26 June 2026 at 13:59:48 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 72 72 0
Self size 21.88 MB 21.68 MB 🎉 -201 KB 🎉
Dependency size 36.44 MB 36.44 MB 0 B
Bundle Size Analyzer Link Link

@storybook/vue3-vite

Before After Difference
Dependency count 102 109 🚨 +7 🚨
Self size 36 KB 36 KB 🎉 -24 B 🎉
Dependency size 42.99 MB 44.15 MB 🚨 +1.16 MB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 204 204 0
Self size 821 KB 821 KB 🚨 +1 B 🚨
Dependency size 91.26 MB 91.06 MB 🎉 -201 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 197 197 0
Self size 32 KB 32 KB 0 B
Dependency size 89.74 MB 89.54 MB 🎉 -201 KB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 73 73 0
Self size 1.09 MB 1.09 MB 🎉 -66 B 🎉
Dependency size 58.32 MB 58.12 MB 🎉 -201 KB 🎉
Bundle Size Analyzer node node

This was referenced Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-scan:automated bug ci:normal Run our default set of CI jobs (choose this for most PRs). qa:skip Pull Requests that do not need any QA. (e.g. documentation) verification:failed

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

@storybook/addon-vitest can miss fast external test completions because TRIGGER_RUN is sent before subscribing

2 participants