@@ -28,30 +28,14 @@ const PreviewModal: React.FC<{
2828 // fix end---------------------
2929
3030 useEffect ( ( ) => {
31- if ( ! isOpen ) return ;
32- //add spinner
33- // if (!isOpen || isLoading) return;
34-
35- // fix start-----------: Get the container element from the ref.
36- // const container = canvasContainerRef.current;
37- // if (!container) {
38- // // This can happen briefly on the first render, so we just wait for the next render.
39- // return;
40- // }
41- // // 3. Check for the required legacy functions on the window object.
42- // if (
43- // typeof window.previewdata !== "function" ||
44- // typeof window.initcanvas_with_container !== "function"
45- // ) {
46- // console.error(
47- // "❌ Legacy preview script functions are not available on the window object."
48- // );
49- // return;
50- // }
51-
52- // window.previewdata(dataKey, previewIndex, isInternal, false);
53- // fix end---------------------------------
54- // clear old canvas
31+ // if (!isOpen) return;
32+ if ( ! isOpen ) {
33+ // Modal just closed — clean up Three.js immediately
34+ if ( typeof window . destroyPreview === "function" ) {
35+ window . destroyPreview ( ) ;
36+ }
37+ return ;
38+ }
5539 const canvasDiv = document . getElementById ( "canvas" ) ;
5640 if ( canvasDiv )
5741 while ( canvasDiv . firstChild ) canvasDiv . removeChild ( canvasDiv . firstChild ) ;
@@ -69,6 +53,10 @@ const PreviewModal: React.FC<{
6953
7054 return ( ) => {
7155 clearInterval ( interval ) ;
56+ // Component unmounting — clean up Three.js
57+ if ( typeof window . destroyPreview === "function" ) {
58+ window . destroyPreview ( ) ;
59+ }
7260 } ;
7361 } , [ isOpen , dataKey , previewIndex , isInternal ] ) ;
7462
0 commit comments