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>
</head>
<body>
<div id="zbChart"></div>
<div id="sbChart"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@ -10,16 +10,29 @@ ModuleRegistry.registerModules([AllCommunityModule]);
declare global {
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 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(
<StrictMode>
<App />
</StrictMode>,
@ -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);

View File

@ -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,
},