Skip to content

Commit 378e328

Browse files
committed
fix: fixing the docs app (COR-4237) (#460)
<!-- You can erase any parts of this template not applicable to your Pull Request. --> **Fixes or implements VF-XXX** ### Brief description. What is this change? <!-- Build up some context for your teammates on the changes made here and potential tradeoffs made and/or highlight any topics for discussion --> ### Implementation details. How do you make this change? <!-- Explain the way/approach you follow to make this change more deeply in order to help your teammates to understand much easier this change --> ### Setup information <!-- Notes regarding local environment. These should note any new configurations, new environment variables, etc. --> ### Deployment Notes <!-- Notes regarding deployment the contained body of work. These should note any db migrations, etc. --> ### Related PRs <!-- List related PRs against other branches --> - https://github.com/voiceflow/XXXXXXXXX/pull/123 ### Checklist - [ ] Breaking changes have been communicated, including: - New required environment variables - Renaming of interfaces (API routes, request/response interface, etc) - [ ] New environment variables have [been deployed](https://www.notion.so/voiceflow/Add-Environment-Variables-be1b0136479f45f1adece7995a7adbfb) - [ ] Appropriate tests have been written - Bug fixes are accompanied by an updated or new test - New features are accompanied by a new test
1 parent 3f12d9b commit 378e328

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

apps/documentation/src/components/StoryEmbed.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@ import type { StoryObj } from '@storybook/react';
22
import type { DecoratorFunction } from '@storybook/types';
33
import { useEffect, useMemo, useState } from 'react';
44

5-
const Stories = typeof window !== 'undefined' ? require('@voiceflow/react-chat/stories') : {};
6-
75
const ComponentNotFound: React.FC = () => <h2>🚨 Component not found! 🚨</h2>;
86

97
export interface IStoryEmbed {
10-
for: keyof typeof Stories;
8+
for: string; // This should be `keyof type Stories` but we load this dynamically
119
name: string;
1210
props?: Record<string, any>;
1311
clientOnly?: boolean;
1412
}
1513

1614
export const StoryEmbed: React.FC<IStoryEmbed> = ({ for: componentName, name, props, clientOnly = false }) => {
17-
const module = Stories[componentName];
18-
const target = (module as any)?.[name] as StoryObj<any>;
1915
const [shouldRender, setShouldRender] = useState(!clientOnly);
16+
const [stories, setStories] = useState<any>();
2017

21-
const decorators = useMemo(
22-
() => (target?.decorators || module?.default.decorators || []) as DecoratorFunction<any>[],
23-
[target?.decorators, module?.default.decorators]
24-
);
18+
useEffect(() => {
19+
const initStories = async () => {
20+
setStories(await import('@voiceflow/react-chat/stories'));
21+
};
22+
initStories();
23+
}, []);
2524

2625
useEffect(() => setShouldRender(true), []);
26+
if (!stories) return null;
27+
28+
const module = stories[componentName] as any;
29+
const target = (module as any)?.[name] as StoryObj<any>;
30+
31+
const decorators = (target?.decorators || module?.default.decorators || []) as DecoratorFunction<any>[];
2732

2833
if (!shouldRender) return null;
2934

0 commit comments

Comments
 (0)