Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defects/issue 3878 #3880

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions packages/mermaid/src/docs/.vitepress/theme/Mermaid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ const props = defineProps({
const svg = ref(null);
let mut = null;

const mermaidConfig = {
securityLevel: 'loose',
startOnLoad: false,
};

onMounted(async () => {
mut = new MutationObserver(() => renderChart());
mut.observe(document.documentElement, { attributes: true });
Expand Down Expand Up @@ -58,9 +53,20 @@ onUnmounted(() => mut.disconnect());
const renderChart = async () => {
console.log('rendering chart' + props.id + props.graph);
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 });
svg.value = await render(props.id, decodeURIComponent(props.graph), mermaidConfig);
let svgCode = await render(props.id, decodeURIComponent(props.graph), mermaidConfig);
// This is a hack to force v-html to re-render, otherwise the diagram disappears
// when **switching themes** or **reloading the page**.
// The cause is that the diagram is deleted during rendering (out of Vue's knowledge).
// Because svgCode does NOT change, v-html does not re-render.
// This is not required for all diagrams, but it is required for c4c, mindmap and zenuml.
const salt = Math.random().toString(36).substring(7);
svg.value = `${svgCode} <span style="display: none">${salt}</span>`;
};
</script>