Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't render with modernInline if inlineStories is false #16853

Merged
merged 2 commits into from Dec 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 37 additions & 37 deletions addons/docs/src/blocks/Story.tsx
Expand Up @@ -157,22 +157,6 @@ const Story: FunctionComponent<StoryProps> = (props) => {
const [rendered, onRendered] = makeGate();
useEffect(onRendered);

// If we are rendering a old-style inline Story via `PureStory` below, we want to emit
// the `STORY_RENDERED` event when it renders. The modern mode below calls out to
// `Preview.renderStoryToDom()` which itself emits the event.
if (story && !global?.FEATURES?.modernInlineRender) {
// We need to wait for two things before we can consider the story rendered:
// (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
// decorators of the form `<A><B/></A>` will not actually execute `B` in the first
// call to the story function.
// (b) The story function needs to actually have been called.
// Certain frameworks (i.e.angular) don't actually render the component in the very first
// React render cycle, so we need to wait for the framework to actually do that
Promise.all([storyFnRan, rendered]).then(() => {
channel.emit(Events.STORY_RENDERED, storyId);
});
}

if (!story) {
return <StorySkeleton />;
}
Expand All @@ -182,27 +166,43 @@ const Story: FunctionComponent<StoryProps> = (props) => {
return null;
}

if (global?.FEATURES?.modernInlineRender) {
// We do this so React doesn't complain when we replace the span in a secondary render
const htmlContents = `<span></span>`;

// FIXME: height/style/etc. lifted from PureStory
const { height } = storyProps;
return (
<div id={storyBlockIdFromId(story.id)}>
<MDXProvider components={resetComponents}>
{height ? (
<style>{`#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`}</style>
) : null}
{showLoader && <StorySkeleton />}
<div
ref={storyRef}
data-name={story.name}
dangerouslySetInnerHTML={{ __html: htmlContents }}
/>
</MDXProvider>
</div>
);
if (storyProps.inline) {
// If we are rendering a old-style inline Story via `PureStory` below, we want to emit
// the `STORY_RENDERED` event when it renders. The modern mode below calls out to
// `Preview.renderStoryToDom()` which itself emits the event.
if (!global?.FEATURES?.modernInlineRender) {
// We need to wait for two things before we can consider the story rendered:
// (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
// decorators of the form `<A><B/></A>` will not actually execute `B` in the first
// call to the story function.
// (b) The story function needs to actually have been called.
// Certain frameworks (i.e.angular) don't actually render the component in the very first
// React render cycle, so we need to wait for the framework to actually do that
Promise.all([storyFnRan, rendered]).then(() => {
channel.emit(Events.STORY_RENDERED, storyId);
});
} else {
// We do this so React doesn't complain when we replace the span in a secondary render
const htmlContents = `<span></span>`;

// FIXME: height/style/etc. lifted from PureStory
const { height } = storyProps;
return (
<div id={storyBlockIdFromId(story.id)}>
<MDXProvider components={resetComponents}>
{height ? (
<style>{`#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`}</style>
) : null}
{showLoader && <StorySkeleton />}
<div
ref={storyRef}
data-name={story.name}
dangerouslySetInnerHTML={{ __html: htmlContents }}
/>
</MDXProvider>
</div>
);
}
}

return (
Expand Down