Skip to content

Commit

Permalink
fix/timeouts (#650)
Browse files Browse the repository at this point in the history
* ⏱extend `react` bundle loading timeout and provide options to allow it tobe set programmatically
* 🧙🏽 make options really optional
* 📚changeset
  • Loading branch information
stevejpurves authored Jul 3, 2023
1 parent 96779c1 commit a19ca30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-lies-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'thebe-react': patch
---

Extend timeout for async loading of the `thebe-core` and `thebe-lite` bundles
12 changes: 9 additions & 3 deletions packages/react/src/ThebeLoaderProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ export function ThebeBundleLoaderProvider({
loadThebeLite,
publicPath,
children,
}: React.PropsWithChildren<{ start?: boolean; loadThebeLite?: boolean; publicPath?: string }>) {
options = {},
}: React.PropsWithChildren<{
start?: boolean;
loadThebeLite?: boolean;
publicPath?: string;
options?: { attempts?: number; delay?: number };
}>) {
const [startLoad, setStartLoad] = useState(start);
const [loading, setLoading] = useState(false);
const [core, setCore] = useState<ThebeCore | undefined>();
Expand Down Expand Up @@ -86,7 +92,7 @@ export function ThebeBundleLoaderProvider({
if (window.thebeLite) console.debug('thebe-lite loaded');
clearInterval(timer);
}
if (attempts > 15) {
if (attempts > (options?.attempts ?? 50)) {
setError('thebe-core load failed');
setLoading(false);
clearInterval(timer);
Expand All @@ -95,7 +101,7 @@ export function ThebeBundleLoaderProvider({
if (!window.thebeLite) console.debug('thebe-lite failed to load');
}
attempts += 1;
}, 300);
}, options?.delay ?? 300);
} catch (err: any) {
setError(err);
setLoading(false);
Expand Down

0 comments on commit a19ca30

Please sign in to comment.