Not sure if this is related to a storybook built using vite or not. But I am dispatching a custom event in a decorator (within an addon) and it works when running storybook locally but not when it's built. It does seem to work when built with webpack though.
Does this make any sense? Any ideas how how to fix?
Decorator
export function sourceDecorator(storyFn: any, context: any) {
const story = context.originalStoryFn(context.args, context);
setTimeout(() =>{
addons
.getChannel()
.emit('franklin/block-rendered', { code: story instanceof HTMLElement ? story.outerHTML : story });
}, 800);
return story;
}
I have to put it in a timeout because my story is rendered async.
Addon Environment (uses webpack for testing and works when built)
Environment Info:
System:
OS: macOS 13.1
CPU: (10) arm64 Apple M1 Max
Binaries:
Node: 18.12.0 - ~/.nvm/versions/node/v18.12.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.0/bin/yarn
npm: 8.19.2 - ~/.nvm/versions/node/v18.12.0/bin/npm
Browsers:
Chrome: 110.0.5481.177
Firefox: 109.0.1
Safari: 16.2
npmPackages:
@storybook/addon-essentials: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/addon-mdx-gfm: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/addons: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/api: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/cli: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/components: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/core-events: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/html: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/html-webpack5: ^7.0.0-beta.63 => 7.0.0-beta.63
@storybook/theming: ^7.0.0-beta.63 => 7.0.0-beta.63