Skip to content

Commit 8997f7c

Browse files
committed
Another fix for race condition
1 parent c954411 commit 8997f7c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

apps/webapp/app/components/TriggerRotatingLogo.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ declare global {
1313
>;
1414
}
1515
}
16+
17+
interface Window {
18+
__splineLoader?: Promise<void>;
19+
}
1620
}
1721

1822
export function TriggerRotatingLogo() {
@@ -25,12 +29,29 @@ export function TriggerRotatingLogo() {
2529
return;
2630
}
2731

32+
// Another mount already started loading - share the same promise
33+
if (window.__splineLoader) {
34+
window.__splineLoader.then(() => setIsSplineReady(true)).catch(() => setIsSplineReady(false));
35+
return;
36+
}
37+
38+
// First mount: create script and shared loader promise
2839
const script = document.createElement("script");
2940
script.type = "module";
41+
// Version pinned; SRI hash omitted as unpkg doesn't guarantee hash stability across deploys
3042
script.src = "https://unpkg.com/@splinetool/[email protected]/build/spline-viewer.js";
31-
script.onload = () => setIsSplineReady(true);
32-
// On error, we simply don't show the decorative viewer - no action needed
43+
44+
window.__splineLoader = new Promise<void>((resolve, reject) => {
45+
script.onload = () => resolve();
46+
script.onerror = () => reject();
47+
});
48+
49+
window.__splineLoader.then(() => setIsSplineReady(true)).catch(() => setIsSplineReady(false));
50+
3351
document.head.appendChild(script);
52+
53+
// Intentionally no cleanup: once the custom element is registered globally,
54+
// removing the script would break re-mounts while providing no benefit
3455
}, []);
3556

3657
if (!isSplineReady) {

0 commit comments

Comments
 (0)