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

refactor(console): load mermaid in dev #6155

Merged
merged 1 commit into from
Jul 2, 2024
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
6 changes: 5 additions & 1 deletion packages/console/src/mdx-components/Mermaid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { useEffect } from 'react';

import useTheme from '@/hooks/use-theme';

/** Load Mermaid asynchronously from jsDelivr to avoid Parcel issues. */
const loadMermaid = async () => {
// Define this variable to "outsmart" the detection of the dynamic import by Parcel:
// https://github.com/parcel-bundler/parcel/issues/7064#issuecomment-942441649
const uri = 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const imported: { default: MermaidType } = await import(uri);
const imported: { default: MermaidType } = await (process.env.NODE_ENV === 'development'
? // eslint-disable-next-line no-eval -- https://github.com/parcel-bundler/parcel/issues/8316
eval(`import('${uri}')`)
: import(uri));
return imported.default;
};

Expand Down
Loading