fix: substitute {{viewMode}} placeholder in setup-page-script#601
Draft
MIreland wants to merge 1 commit into
Draft
fix: substitute {{viewMode}} placeholder in setup-page-script#601MIreland wants to merge 1 commit into
MIreland wants to merge 1 commit into
Conversation
`setup-page-script.ts` declares `TEST_RUNNER_VIEW_MODE = '{{viewMode}}'`
and passes it to `setCurrentStory` on every navigation, but `setupPage`
in `setup-page.ts` never replaced the placeholder before injecting the
script — leaving the browser with the literal string `"{{viewMode}}"`.
When Storybook 8+ receives an unknown `viewMode` value it syncs it into
the iframe URL (`?viewMode={{viewMode}}`), which can trigger a hard
navigation that destroys Playwright's execution context mid-test,
producing intermittent "page.evaluate: Execution context was destroyed"
failures with no obvious cause.
Fix: add `.replaceAll('{{viewMode}}', viewMode)` to the substitution
chain alongside the other placeholders. `viewMode` is already computed
on the line above from `process.env.VIEW_MODE ?? 'story'`.
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.
(LLM-powered WIP, I will clean up the PR description shortly)
Problem
setup-page-script.tsdeclares:and emits it on every story navigation:
But
setupPageinsetup-page.tsnever replaces{{viewMode}}before injecting the script. All other placeholders ({{storybookUrl}},{{failOnConsole}},{{renderedEvent}}, etc.) are substituted —{{viewMode}}was simply missing from the chain.Effect
The browser receives the literal string
"{{viewMode}}"as theviewModeargument tosetCurrentStory. Storybook 8+ syncs this into the iframe URL as?viewMode=%7B%7BviewMode%7D%7D. When an unknownviewModeis set, Storybook can trigger a hard iframe navigation mid-test, which destroys Playwright's execution context and produces:This failure is intermittent (depends on timing of the navigation vs. the script evaluation) and has no obvious stack trace pointing at the root cause, making it appear as general test flakiness.
Diagnostic evidence: every
setCurrentStoryNAV event carriedviewMode=%7B%7BviewMode%7D%7Dliterally; the runner'scatch → resetPage()retry branch fired 2 seconds later — matching the exact retry signature in@playwright/test's jestPlaywright integration.Fix
Add
.replaceAll('{{viewMode}}', viewMode)to the substitution chain.viewModeis already computed two lines above fromprocess.env.VIEW_MODE ?? 'story'.Testing
Verified by running the test-runner against a Storybook 8 instance with
VIEW_MODE=story(default). ThesetCurrentStoryevents now carryviewMode: "story"and the intermittent navigation-destroy failures no longer occur.