This commit is contained in:
wintsa 2026-05-14 16:43:53 +08:00
parent 6d25ac942f
commit 1d12668e9b
3 changed files with 32 additions and 7 deletions

View File

@ -6,7 +6,7 @@
<title>AG Chart Service</title> <title>AG Chart Service</title>
</head> </head>
<body> <body>
<div id="zbChart"></div> <div id="sbChart"></div>
<script type="module" src="/src/main.tsx"></script> <script type="module" src="/src/main.tsx"></script>
</body> </body>
</html> </html>

View File

@ -10,16 +10,29 @@ ModuleRegistry.registerModules([AllCommunityModule]);
declare global { declare global {
interface Window { interface Window {
__zbChartRoot?: ReturnType<typeof createRoot>; __chartReactRoots?: WeakMap<Element, ReturnType<typeof createRoot>>;
} }
} }
const chartContainerId = 'sbChart';
const getRootRegistry = () => {
window.__chartReactRoots ??= new WeakMap<Element, ReturnType<typeof createRoot>>();
return window.__chartReactRoots;
};
const mount = () => { const mount = () => {
const container = document.getElementById('zbChart'); const container = document.getElementById(chartContainerId);
if (!container) return false; if (!container) return false;
window.__zbChartRoot ??= createRoot(container); const roots = getRootRegistry();
window.__zbChartRoot.render( let root = roots.get(container);
if (!root) {
root = createRoot(container);
roots.set(container, root);
}
root.render(
<StrictMode> <StrictMode>
<App /> <App />
</StrictMode>, </StrictMode>,
@ -34,7 +47,7 @@ if (!mount()) {
if (mount() || retryCount >= 40) { if (mount() || retryCount >= 40) {
window.clearInterval(timer); window.clearInterval(timer);
if (retryCount >= 40) { if (retryCount >= 40) {
console.warn('zbChart container was not found.'); console.warn(`${chartContainerId} container was not found.`);
} }
} }
}, 50); }, 50);

View File

@ -2,7 +2,19 @@ import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react'; import react from '@vitejs/plugin-react';
export default defineConfig({ 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: { server: {
port: 5173, port: 5173,
}, },