Skip to content

Commit f7cb7ad

Browse files
fix: dont initialize mermaid
1 parent 16781e6 commit f7cb7ad

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

components/CodeTabs/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ interface Props {
1414
const CodeTabs = (props: Props) => {
1515
const { children } = props;
1616
const theme = useContext(ThemeContext);
17-
17+
const hasMermaid = !Array.isArray(children) && children.props?.children.props.lang === 'mermaid';
1818

1919
// render Mermaid diagram
2020
useEffect(() => {
21-
if (typeof window !== 'undefined') {
21+
if (typeof window !== 'undefined' && hasMermaid) {
2222
import('mermaid').then(module => {
2323
mermaid = module.default;
2424
mermaid.initialize({
@@ -27,7 +27,7 @@ const CodeTabs = (props: Props) => {
2727
mermaid.contentLoaded();
2828
});
2929
}
30-
}, [theme]);
30+
}, [hasMermaid, theme]);
3131

3232
function handleClick({ target }, index: number) {
3333
const $wrap = target.parentElement.parentElement;
@@ -42,7 +42,7 @@ const CodeTabs = (props: Props) => {
4242
}
4343

4444
// render single Mermaid diagram
45-
if (!Array.isArray(children) && children.props?.children.props.lang === 'mermaid') {
45+
if (hasMermaid) {
4646
const value = children.props.children.props.value;
4747
return <pre className="mermaid mermaid_single">{value}</pre>;
4848
}

0 commit comments

Comments
 (0)