Skip to content

Commit 25afe7b

Browse files
Destroy UnicornStudio on component destroy
Import onDestroy from svelte and destroy UnicornStudio in the onDestroy hook to prevent leaks.
1 parent 47796ab commit 25afe7b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/lib/profiles/(unauthenticated)/studio.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { Typography, Card } from '@appwrite.io/pink-svelte';
55
import { resolvedProfile } from '$lib/profiles/index.svelte';
66
import UnicornScene from './studio.json?url';
7-
import { onMount } from 'svelte';
7+
import { onDestroy, onMount } from 'svelte';
88
import { Tween } from 'svelte/motion';
99
1010
async function isUnicornAvailable() {
@@ -21,12 +21,18 @@
2121
const opacity = new Tween(0);
2222
2323
onMount(async () => {
24+
if ('UnicornStudio' in window) delete window.UnicornStudio;
2425
await isUnicornAvailable();
2526
// @ts-expect-error the typings are trash
2627
// eslint-disable-next-line no-undef
2728
await UnicornStudio.init();
2829
opacity.target = 1;
2930
});
31+
32+
onDestroy(() => {
33+
// @ts-expect-error the typings are trash
34+
delete window.UnicornStudio;
35+
});
3036
</script>
3137

3238
<svelte:head>

0 commit comments

Comments
 (0)