Made mermaidConfig a local variable so that it cannot be shared cross rendering.

This commit is contained in:
MrCoder
2022-12-06 19:44:14 +11:00
parent a1e4ffb3f0
commit 7a086890fd
2 changed files with 6 additions and 9 deletions

View File

@@ -20,11 +20,6 @@ const props = defineProps({
const svg = ref(null); const svg = ref(null);
let mut = null; let mut = null;
const mermaidConfig = {
securityLevel: 'loose',
startOnLoad: false,
};
onMounted(async () => { onMounted(async () => {
mut = new MutationObserver(() => renderChart()); mut = new MutationObserver(() => renderChart());
mut.observe(document.documentElement, { attributes: true }); mut.observe(document.documentElement, { attributes: true });
@@ -58,7 +53,11 @@ onUnmounted(() => mut.disconnect());
const renderChart = async () => { const renderChart = async () => {
console.log('rendering chart' + props.id + props.graph); console.log('rendering chart' + props.id + props.graph);
const hasDarkClass = document.documentElement.classList.contains('dark'); const hasDarkClass = document.documentElement.classList.contains('dark');
mermaidConfig.theme = hasDarkClass ? 'dark' : 'default'; const mermaidConfig = {
securityLevel: 'loose',
startOnLoad: false,
theme: hasDarkClass ? 'dark' : 'default',
};
console.log({ mermaidConfig }); console.log({ mermaidConfig });
let svgCode = await render(props.id, decodeURIComponent(props.graph), mermaidConfig); let svgCode = await render(props.id, decodeURIComponent(props.graph), mermaidConfig);

View File

@@ -8,9 +8,7 @@ try {
} }
export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => { export const render = async (id: string, code: string, config: MermaidConfig): Promise<string> => {
// make a clone of config, so we don't mutate the original mermaid.initialize(config);
const mermaidConfig = { ...config };
mermaid.initialize(mermaidConfig);
const svg = await mermaid.renderAsync(id, code); const svg = await mermaid.renderAsync(id, code);
return svg; return svg;
}; };