Skip to content

Commit

Permalink
Stop getting addons channel from @storybook/addons
Browse files Browse the repository at this point in the history
We're seeing issues where the addons channel exported by
@storybook/addons is different from the globally available channel
window.__STORYBOOK_ADDONS_CHANNEL__.

In the past, we used the global variable but switched to importing it in
05328d7. I can't recall the details there but seems safe to
move back.

I have manually checked that this fixes things for one of our customer.
The symptoms were that all stories appeared to be rendered but they
didn't actually render on screen. Switching to the global channel did
the trick.
  • Loading branch information
trotzig committed Mar 22, 2023
1 parent 853370f commit 5a9d610
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/register.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { addons } from '@storybook/addons';

const { SB_ROOT_ELEMENT_SELECTOR } = require('./constants');

const time = window.happoTime || {
Expand Down Expand Up @@ -163,21 +161,20 @@ window.happo.nextExample = async () => {
console.error('Failed to invoke afterScreenshot hook', e);
}
}
const channel = addons.getChannel();
channel.emit('setCurrentStory', {
window.__STORYBOOK_ADDONS_CHANNEL__.emit('setCurrentStory', {
kind: component,
story: variant,
storyId,
});
await new Promise((resolve) => time.originalSetTimeout(resolve, 0));
if (theme && themeSwitcher) {
await themeSwitcher(theme, channel);
await themeSwitcher(theme, window.__STORYBOOK_ADDONS_CHANNEL__);
}
await waitForSomeContent(rootElement);
if (/sb-show-errordisplay/.test(document.body.className)) {
// It's possible that the error is from unmounting the previous story. We
// can try re-rendering in this case.
channel.emit('forceReRender');
window.__STORYBOOK_ADDONS_CHANNEL__.emit('forceReRender');
await waitForSomeContent(rootElement);
}
if (beforeScreenshot && typeof beforeScreenshot === 'function') {
Expand Down

0 comments on commit 5a9d610

Please sign in to comment.