App React: Ensure that STORY_RENDERED is emitted only after calling storyFn

This commit is contained in:
Hypnosphi 2019-08-17 17:24:53 +02:00
parent 0f330e2c82
commit 149cebaf43
2 changed files with 14 additions and 10 deletions

View File

@ -7,14 +7,16 @@ import { RenderMainArgs } from './types';
const rootEl = document ? document.getElementById('root') : null;
function render(node: React.ReactElement, el: Element) {
const render = (node: React.ReactElement, el: Element) =>
new Promise(resolve => {
ReactDOM.render(
process.env.STORYBOOK_EXAMPLE_APP ? <React.StrictMode>{node}</React.StrictMode> : node,
el
el,
resolve
);
}
});
export default function renderMain({
export default async function renderMain({
storyFn: StoryFn,
selectedKind,
selectedStory,
@ -55,6 +57,6 @@ export default function renderMain({
ReactDOM.unmountComponentAtNode(rootEl);
}
render(element, rootEl);
await render(element, rootEl);
showMain();
}

View File

@ -226,8 +226,10 @@ export default function start(render, { decorateStory } = {}) {
case 'story':
default: {
if (getDecorated) {
render(renderContext);
(async () => {
await render(renderContext);
addons.getChannel().emit(Events.STORY_RENDERED, id);
})();
} else {
showNopreview();
addons.getChannel().emit(Events.STORY_MISSING, id);