diff --git a/src/components/3d/PublicPreview.svelte b/src/components/3d/PublicPreview.svelte index 46ae07a..26811da 100644 --- a/src/components/3d/PublicPreview.svelte +++ b/src/components/3d/PublicPreview.svelte @@ -37,6 +37,7 @@ let renderer: THREE.WebGLRenderer; let controls: OrbitControls; let light: THREE.AmbientLight; + let observer: ResizeObserver; onMount(() => { scene = new THREE.Scene(); @@ -70,7 +71,8 @@ light = new THREE.AmbientLight(0xffffff, 1); scene.add(light); - new ResizeObserver(handleResize).observe(div); + observer = new ResizeObserver(handleResize); + observer.observe(div); loaded = true; @@ -91,6 +93,9 @@ if (loaded) { loaded = false; + observer.unobserve(div); + observer.disconnect(); + renderer.dispose(); scene.clear(); light.dispose();