1
This commit is contained in:
parent
6d25ac942f
commit
1d12668e9b
@ -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>
|
||||
|
||||
23
src/main.tsx
23
src/main.tsx
@ -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);
|
||||
|
||||
@ -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,
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user