This commit is contained in:
Tom Coleman 2022-05-09 17:14:10 +10:00
parent 9c087dc4b5
commit eca0918cf4
3 changed files with 8 additions and 16 deletions

View File

@ -82,9 +82,7 @@ export class ExternalPreview<TFramework extends AnyFramework> extends Preview<TF
}
storyById(storyId: StoryId) {
console.log({ storyId });
const entry = this.storyIndex.entries[storyId];
if (!entry) console.trace();
if (!entry) throw new Error(`Unknown storyId ${storyId}`);
const { importPath, title } = entry;
const moduleExports = this.moduleExportsByImportPath[importPath];

View File

@ -133,18 +133,12 @@ const Story: FunctionComponent<StoryProps> = (props) => {
const story = useStory(storyId, context);
const [showLoader, setShowLoader] = useState(true);
// FIXME: do we need this?
// Register the story with the context, which is needed by external rendering
// context.addStory(of, false);
useEffect(() => {
let cleanup: () => void;
if (storyRef.current) {
if (story && storyRef.current) {
const element = storyRef.current as HTMLElement;
if (story) {
cleanup = context.renderStoryToElement(story, element);
setShowLoader(false);
}
cleanup = context.renderStoryToElement(story, element);
setShowLoader(false);
}
return () => cleanup && cleanup();
}, [story]);
@ -171,15 +165,15 @@ const Story: FunctionComponent<StoryProps> = (props) => {
// FIXME: height/style/etc. lifted from PureStory
const { height } = storyProps;
return (
<div id={storyBlockIdFromId(story?.id)}>
<div id={storyBlockIdFromId(story.id)}>
<MDXProvider components={resetComponents}>
{height ? (
<style>{`#story--${story?.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`}</style>
<style>{`#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`}</style>
) : null}
{showLoader && <StorySkeleton />}
<div
ref={storyRef}
data-name={story?.name}
data-name={story.name}
dangerouslySetInnerHTML={{ __html: htmlContents }}
/>
</MDXProvider>
@ -202,7 +196,7 @@ const Story: FunctionComponent<StoryProps> = (props) => {
}
return (
<div id={storyBlockIdFromId(story?.id)}>
<div id={storyBlockIdFromId(story.id)}>
<MDXProvider components={resetComponents}>
<PureStory {...storyProps} />
</MDXProvider>

View File

@ -81,7 +81,7 @@ export class DocsRender<TFramework extends AnyFramework> implements Render<TFram
viewMode: 'docs' as ViewMode,
} as StoryContextForLoaders<TFramework>),
// These three are intended for external renders only
// These is intended for the external docs render only
setMeta: () => {},
};