From e380b05bb2d2cf454f634df8e3b919c108b23b0a Mon Sep 17 00:00:00 2001 From: Anton Pascal Date: Tue, 21 Jul 2026 04:08:14 +0000 Subject: [PATCH] fix(editor): polyfill structuredClone for legacy browsers --- apps/editor/instrumentation-client.ts | 1 + apps/editor/lib/polyfills/structured-clone.ts | 5 +++++ apps/editor/package.json | 1 + apps/editor/types/ungap-structured-clone.d.ts | 8 ++++++++ bun.lock | 3 +++ 5 files changed, 18 insertions(+) create mode 100644 apps/editor/instrumentation-client.ts create mode 100644 apps/editor/lib/polyfills/structured-clone.ts create mode 100644 apps/editor/types/ungap-structured-clone.d.ts diff --git a/apps/editor/instrumentation-client.ts b/apps/editor/instrumentation-client.ts new file mode 100644 index 000000000..1b7554aa4 --- /dev/null +++ b/apps/editor/instrumentation-client.ts @@ -0,0 +1 @@ +import './lib/polyfills/structured-clone' diff --git a/apps/editor/lib/polyfills/structured-clone.ts b/apps/editor/lib/polyfills/structured-clone.ts new file mode 100644 index 000000000..f42b5c062 --- /dev/null +++ b/apps/editor/lib/polyfills/structured-clone.ts @@ -0,0 +1,5 @@ +import structuredClonePolyfill from '@ungap/structured-clone' + +if (typeof globalThis.structuredClone !== 'function') { + globalThis.structuredClone = structuredClonePolyfill +} diff --git a/apps/editor/package.json b/apps/editor/package.json index 862df6503..fae671663 100644 --- a/apps/editor/package.json +++ b/apps/editor/package.json @@ -23,6 +23,7 @@ "@react-three/drei": "^10.7.7", "@react-three/fiber": "^9.5.0", "@tailwindcss/postcss": "^4.2.1", + "@ungap/structured-clone": "^1.3.3", "clsx": "^2.1.1", "geist": "^1.7.0", "lucide-react": "^1.7.0", diff --git a/apps/editor/types/ungap-structured-clone.d.ts b/apps/editor/types/ungap-structured-clone.d.ts new file mode 100644 index 000000000..5ea9c81c4 --- /dev/null +++ b/apps/editor/types/ungap-structured-clone.d.ts @@ -0,0 +1,8 @@ +declare module '@ungap/structured-clone' { + type StructuredCloneOptions = StructuredSerializeOptions & { + json?: boolean + lossy?: boolean + } + + export default function structuredClone(value: T, options?: StructuredCloneOptions): T +} diff --git a/bun.lock b/bun.lock index 2a57c1e64..c60d765c6 100644 --- a/bun.lock +++ b/bun.lock @@ -39,6 +39,7 @@ "@react-three/drei": "^10.7.7", "@react-three/fiber": "^9.5.0", "@tailwindcss/postcss": "^4.2.1", + "@ungap/structured-clone": "^1.3.3", "clsx": "^2.1.1", "geist": "^1.7.0", "lucide-react": "^1.7.0", @@ -924,6 +925,8 @@ "@typescript/native-preview-win32-x64": ["@typescript/native-preview-win32-x64@7.0.0-dev.20260624.1", "", { "os": "win32", "cpu": "x64" }, "sha512-WaZ+ue63NgB2j/lqjirfevh/TqcsCxSqnKhGGiRnlxHyYIBcoq+x7KngyEnyGIaywJE1PcFeXA+2EMSIPlSEiQ=="], + "@ungap/structured-clone": ["@ungap/structured-clone@1.3.3", "", {}, "sha512-60YRaenCQcVjYEKOcG824+DRGGIQ3VKErcBoAEDJZz5bKIs2ZG+X/H9Nk+Q6EVkwJk5QNApxbrc5QtBSwtrXAg=="], + "@use-gesture/core": ["@use-gesture/core@10.3.1", "", {}, "sha512-WcINiDt8WjqBdUXye25anHiNxPc0VOrlT8F6LLkU6cycrOGUDyY/yyFmsg3k8i5OLvv25llc0QC45GhR/C8llw=="], "@use-gesture/react": ["@use-gesture/react@10.3.1", "", { "dependencies": { "@use-gesture/core": "10.3.1" }, "peerDependencies": { "react": ">= 16.8.0" } }, "sha512-Yy19y6O2GJq8f7CHf7L0nxL8bf4PZCPaVOCgJrusOeFHY1LvHgYXnmnXg6N5iwAnbgbZCDjo60SiM6IPJi9C5g=="],