Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.5.7",
"@types/pako": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^5.31.0",
Expand Down
36 changes: 12 additions & 24 deletions src/components/PreviewModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,14 @@ const PreviewModal: React.FC<{
// fix end---------------------

useEffect(() => {
if (!isOpen) return;
//add spinner
// if (!isOpen || isLoading) return;

// fix start-----------: Get the container element from the ref.
// const container = canvasContainerRef.current;
// if (!container) {
// // This can happen briefly on the first render, so we just wait for the next render.
// return;
// }
// // 3. Check for the required legacy functions on the window object.
// if (
// typeof window.previewdata !== "function" ||
// typeof window.initcanvas_with_container !== "function"
// ) {
// console.error(
// "❌ Legacy preview script functions are not available on the window object."
// );
// return;
// }

// window.previewdata(dataKey, previewIndex, isInternal, false);
// fix end---------------------------------
// clear old canvas
// if (!isOpen) return;
if (!isOpen) {
// Modal just closed — clean up Three.js immediately
if (typeof window.destroyPreview === "function") {
window.destroyPreview();
}
return;
}
const canvasDiv = document.getElementById("canvas");
if (canvasDiv)
while (canvasDiv.firstChild) canvasDiv.removeChild(canvasDiv.firstChild);
Expand All @@ -69,6 +53,10 @@ const PreviewModal: React.FC<{

return () => {
clearInterval(interval);
// Component unmounting — clean up Three.js
if (typeof window.destroyPreview === "function") {
window.destroyPreview();
}
};
}, [isOpen, dataKey, previewIndex, isInternal]);

Expand Down
Loading
Loading