diff --git a/app/react/src/client/preview/render.tsx b/app/react/src/client/preview/render.tsx index c3d5eff30059..36068d6c09bf 100644 --- a/app/react/src/client/preview/render.tsx +++ b/app/react/src/client/preview/render.tsx @@ -7,14 +7,16 @@ import { RenderMainArgs } from './types'; const rootEl = document ? document.getElementById('root') : null; -function render(node: React.ReactElement, el: Element) { - ReactDOM.render( - process.env.STORYBOOK_EXAMPLE_APP ? {node} : node, - el - ); -} +const render = (node: React.ReactElement, el: Element) => + new Promise(resolve => { + ReactDOM.render( + process.env.STORYBOOK_EXAMPLE_APP ? {node} : node, + 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(); } diff --git a/examples/official-storybook/stories/demo/button.stories.js b/examples/official-storybook/stories/demo/button.stories.js index 274eb231df08..3de9125d4882 100644 --- a/examples/official-storybook/stories/demo/button.stories.js +++ b/examples/official-storybook/stories/demo/button.stories.js @@ -1,10 +1,35 @@ import React, { useState } from 'react'; import { action } from '@storybook/addon-actions'; import { Button } from '@storybook/react/demo'; +import { useChannel, useState as useStoryState } from '@storybook/client-api'; + +const withPropsInfo = storyFn => { + const [selected, setSelected] = useStoryState(true); + + const emit = useChannel( + { + REQUEST_PROPS_CHANGE: () => setSelected(!selected), + }, + [selected] + ); + + console.log('SELECTED:', selected); + + return ( +
+ {storyFn()} + {selected && 'Article'} + +
+ ); +}; export default { title: 'Other|Demo/Button', component: Button, + decorators: [withPropsInfo], }; export const withText = () => ; diff --git a/lib/core/src/client/preview/start.js b/lib/core/src/client/preview/start.js index 36d0bfe9b584..20fb190b7b1a 100644 --- a/lib/core/src/client/preview/start.js +++ b/lib/core/src/client/preview/start.js @@ -226,8 +226,10 @@ export default function start(render, { decorateStory } = {}) { case 'story': default: { if (getDecorated) { - render(renderContext); - addons.getChannel().emit(Events.STORY_RENDERED, id); + (async () => { + await render(renderContext); + addons.getChannel().emit(Events.STORY_RENDERED, id); + })(); } else { showNopreview(); addons.getChannel().emit(Events.STORY_MISSING, id);