mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 07:21:16 +08:00
App React: Ensure that STORY_RENDERED is emitted only after calling storyFn
This commit is contained in:
parent
0f330e2c82
commit
149cebaf43
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user