-
Notifications
You must be signed in to change notification settings - Fork 82
[Feature request]: Change globals before rendering story #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
we need this, too! |
@shilman using the updated hooks, previsit and postvisit.. ^ the workaround indicated above won't work anymore. is there anyway this feature can be accommodated..? we wanna be able to take snapshots of components in different languages WITHOUT having to duplicate stories in a different language. 🙏 |
We are considering porting story modes from Chromatic to Storybook. Would that solve your needs? |
@shilman yup, this definitely will! do we know when this may happen? will it be in Storybook v9? |
This is the magic that allows you to switch modes: import type { Page } from "playwright";
import type { Channel } from "@storybook/core/channels";
interface StorybookGlobaThis {
__STORYBOOK_PREVIEW__: {
channel: Channel;
};
}
export async function setStorybookGlobals(
page: Page,
globals: Record<string, unknown>
) {
await page.evaluate((g) => {
const channel = (globalThis as unknown as StorybookGlobaThis)
.__STORYBOOK_PREVIEW__.channel;
channel.emit("updateGlobals", {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
globals: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
...channel.last("globalsUpdated")?.[0].initialGlobals,
...g,
},
});
}, globals);
} |
Is your feature request related to a problem? Please describe.
Hey all,
I've been using a decorator + global types to support locales on our stories:
In the stories we allow to define supported languages for visual regression tests:
What I am trying to achieve is to use one of the existing hooks from test runners to set the globals before rendering the story based on these configured parameters, the solution I've found out so far was to read current page URL and set the globals using query parameter, but that brings a lot of overhead since for each language the page needs to be reloaded:
Describe the solution you'd like
What would be the best way to set these globals for the story before it's rendered based on these parameters?
Not to mention we are going to have multiple breakpoints too, which could exponentially increase test timeouts.
Describe alternatives you've considered
No response
Are you able to assist to bring the feature to reality?
no
Additional context
No response
The text was updated successfully, but these errors were encountered: