From 1d12668e9b1237a66cc7df5f1740fb8f0db87dd9 Mon Sep 17 00:00:00 2001 From: wintsa <770775984@qq.com> Date: Thu, 14 May 2026 16:43:53 +0800 Subject: [PATCH] 1 --- index.html | 2 +- src/main.tsx | 23 ++++++++++++++++++----- vite.config.ts | 14 +++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 4ed0f49..69daf8b 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,7 @@ AG Chart Service -
+
diff --git a/src/main.tsx b/src/main.tsx index e64567a..01bf720 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -10,16 +10,29 @@ ModuleRegistry.registerModules([AllCommunityModule]); declare global { interface Window { - __zbChartRoot?: ReturnType; + __chartReactRoots?: WeakMap>; } } +const chartContainerId = 'sbChart'; + +const getRootRegistry = () => { + window.__chartReactRoots ??= new WeakMap>(); + return window.__chartReactRoots; +}; + const mount = () => { - const container = document.getElementById('zbChart'); + const container = document.getElementById(chartContainerId); if (!container) return false; - window.__zbChartRoot ??= createRoot(container); - window.__zbChartRoot.render( + const roots = getRootRegistry(); + let root = roots.get(container); + if (!root) { + root = createRoot(container); + roots.set(container, root); + } + + root.render( , @@ -34,7 +47,7 @@ if (!mount()) { if (mount() || retryCount >= 40) { window.clearInterval(timer); if (retryCount >= 40) { - console.warn('zbChart container was not found.'); + console.warn(`${chartContainerId} container was not found.`); } } }, 50); diff --git a/vite.config.ts b/vite.config.ts index 5c59447..5bd8cc1 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -2,7 +2,19 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; export default defineConfig({ - plugins: [react()], + plugins: [ + react(), + { + name: 'weaver-script-scope-wrapper', + renderChunk(code, chunk) { + if (!chunk.isEntry) return null; + return { + code: `;(() => {\n${code}\n})();\n`, + map: null, + }; + }, + }, + ], server: { port: 5173, },