A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
display mermaid error if present and strip diagram (#8368)
Shahmir Varqhaba33e0751851
diff --git a/frontend/src/plugins/layout/mermaid/mermaid.tsx b/frontend/src/plugins/layout/mermaid/mermaid.tsxindex b6a61e8fa8..a86a2cae8e 100644--- a/frontend/src/plugins/layout/mermaid/mermaid.tsx+++ b/frontend/src/plugins/layout/mermaid/mermaid.tsx@@ -4,6 +4,7 @@ import type { MermaidConfig } from "mermaid";import mermaid from "mermaid";import React, { useState } from "react";import { useAsyncData } from "@/hooks/useAsyncData";+import { ErrorBanner } from "@/plugins/impl/common/error-banner";import { useTheme } from "@/theme/useTheme";import { Logger } from "@/utils/Logger";@@ -72,9 +73,12 @@ const Mermaid: React.FC<Props> = ({ diagram }) => {darkMode: darkMode,});- const { data: svg } = useAsyncData(async () => {+ // Frontmatter does not work with newlines, so we trim the diagram to avoid these errors+ const trimmedDiagram = diagram.trim();++ const { data: svg, error } = useAsyncData(async () => {const result = await mermaid- .render(id, diagram, undefined)+ .render(id, trimmedDiagram, undefined).catch((error) => {document.getElementById(id)?.remove();Logger.warn("Failed to render mermaid diagram", error);@@ -82,7 +86,11 @@ const Mermaid: React.FC<Props> = ({ diagram }) => {});return result.svg;- }, [diagram, id, darkMode]);+ }, [trimmedDiagram, id, darkMode]);++ if (error) {+ return <ErrorBanner error={error} />;+ }if (!svg) {return null;diff --git a/pyproject.toml b/pyproject.tomlindex e88aedc9bf..767bc2c6fe 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -557,7 +557,8 @@ extend-exclude = ["**/__demo__/*","base64.test.ts","SECURITY.md", # Contains usernames that trigger typos- "patches/*", # Patches may contain typos from source code+ "patches/*", # Patches may contain typos from source code,+ "frontend/dist/assets/*", # Assets may contain typos from source code"tests/_sql/test_sql_parse.py", # Contains intentional invalid SQL for testing]