fix(storybook-addon-vis): await the vitest module load before using the proxies - #849
Merged
Merged
Conversation
…he proxies `commands` and `page` are populated by a dynamic import that nothing awaited, so a hook reading `commands.setupVisSuite` before it settled got `undefined` and failed with `commands.setupVisSuite is not a function` — inside a run that genuinely is vitest browser mode. The imports stay dynamic (this module is also reached from a plain Storybook preview, where the vitest modules do not exist), but the ordering is now enforced: - a command read before the import settles returns a function that waits for it and then delegates, instead of `undefined` - `whenVitestProxyReady()` exposes the load, and the addon's `beforeAll` awaits it before reading `page` or the current test `createVitestProxy` is exported so the pending window can be driven directly in a test; the module-level proxy's import has long settled by then. Closes #835 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NLB1dHgUEekHmMNj4G7R63
🦋 Changeset detectedLatest commit: f450ead The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #835.
Problem
src/client/vitest_proxy.tspopulatedcommandsandpagefrom a dynamic import that nothing awaited. Until it settled,browserContextwasundefinedand every property read through thecommandsproxy returnedundefined— so the addon'sbeforeAllreadingcommands.setupVisSuitecould fail withcommands.setupVisSuite is not a functioninside a run that genuinely is vitest browser mode. Ordering, not detection; the #829 guard is untouched.Why the import stays dynamic
src/index.tsis the Storybook preview annotation entry, so this module is also evaluated in a plain Storybook preview wherevitestandvitest/browserare not available. Hoisting to a static import (or a top-level await) would break that, so the fix enforces the ordering instead of removing the asynchrony.Fix
vis.setup()viastorybook-addon-vis/vitest-setup— without each call site opting in.whenVitestProxyReady()exposes the load, and the addon'sbeforeAllawaits it beforepageandgetCurrentTest(both read synchronously, so they cannot defer themselves).commandskeeps yieldingundefined, so the isRunningInTest check causes problems during agentic debugging #829 guards stay in charge.Test
The timing is not observable on the module-level proxy (its import has long settled by the time a test runs), so
createVitestProxyis exported and driven with loaders that stay pending until the test resolves them — the ordering is proven directly rather than raced.Reverting only the proxy change turns 3 of the 7 new tests red (
expected 'undefined' to be 'function'). Full package suite: 83 passed, pluspnpm build,tsc --noEmit, andbiome checkclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01NLB1dHgUEekHmMNj4G7R63