Skip to content

🎥 Make videos programmatically with React

catch error on bundle homepage

Jonny Burgere65d6a3baa28
diff --git a/packages/bundler/src/homepage/homepage.tsx b/packages/bundler/src/homepage/homepage.tsx
index a8b3a57ebf..afe540396a 100644
--- a/packages/bundler/src/homepage/homepage.tsx
+++ b/packages/bundler/src/homepage/homepage.tsx
@@ -23,8 +23,26 @@ const pre: React.CSSProperties = {
overflowX: 'auto',
};
+type CompositionState =
+ | {
+ type: 'not-initialized';
+ }
+ | {
+ type: 'loading';
+ }
+ | {
+ type: 'loaded';
+ comps: AnyCompMetadata[];
+ }
+ | {
+ type: 'error';
+ error: Error;
+ };
+
const AvailableCompositions: React.FC = () => {
- const [comps, setComps] = useState<AnyCompMetadata[] | null>(null);
+ const [state, setComps] = useState<CompositionState>({
+ type: 'not-initialized',
+ });
useEffect(() => {
if (getBundleMode().type !== 'evaluation') {
@@ -34,9 +52,14 @@ const AvailableCompositions: React.FC = () => {
let timeout: NodeJS.Timeout | null = null;
const check = () => {
if (window.ready === true) {
- window.getStaticCompositions().then((newComps) => {
- setComps(newComps);
- });
+ setComps({type: 'loading'});
+
+ window
+ .getStaticCompositions()
+ .then((newComps) => {
+ setComps({type: 'loaded', comps: newComps});
+ })
+ .catch((err) => ({type: 'error', error: err}));
} else {
timeout = setTimeout(check, 250);
}
@@ -65,13 +88,24 @@ const AvailableCompositions: React.FC = () => {
);
}
+ if (state.type === 'loading') {
+ return <div>{state === null ? <p>Loading compositions...</p> : null}</div>;
+ }
+
+ if (state.type === 'error') {
+ return <div>Error loading compositions: {state.error.stack}</div>;
+ }
+
+ if (state.type === 'not-initialized') {
+ return <div>Not initialized</div>;
+ }
+
return (
<div>
- {comps === null ? <p>Loading compositions...</p> : null}
<ul>
- {comps === null
+ {state === null
? []
- : comps.map((c) => {
+ : state.comps.map((c) => {
return <li key={c.id}>{c.id}</li>;
})}
</ul>