From ca0637cc6eac9685946a62458d7b9d9dc5232a77 Mon Sep 17 00:00:00 2001 From: Antigravity Date: Fri, 22 May 2026 18:33:55 +0000 Subject: [PATCH] fix(chart): prevent infinite loops and remove hardcoded text - Memoize ChartWrapper to prevent infinite re-renders in MarkdownContent - Remove hardcoded French text (multilingual app) - Return null for invalid charts instead of error messages --- memento-note/components/markdown-content.tsx | 12 +++++++++--- memento-note/components/note-chart.tsx | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/memento-note/components/markdown-content.tsx b/memento-note/components/markdown-content.tsx index 5fadd44..ac8a41f 100644 --- a/memento-note/components/markdown-content.tsx +++ b/memento-note/components/markdown-content.tsx @@ -1,6 +1,6 @@ 'use client' -import { memo } from 'react' +import { memo, useMemo } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import remarkMath from 'remark-math' @@ -9,6 +9,11 @@ import rehypeRaw from 'rehype-raw' import 'katex/dist/katex.min.css' import { NoteChartFromCode } from './note-chart' +// Memoized wrapper to prevent infinite re-renders +const ChartWrapper = memo(function ChartWrapper({ code }: { code: string }) { + return +}) + interface MarkdownContentProps { content: string className?: string @@ -28,9 +33,10 @@ export const MarkdownContent = memo(function MarkdownContent({ content, classNam const match = /language-(\w+)/.exec(className || '') const language = match ? match[1] : '' - // Chart code blocks + // Chart code blocks - memoized to prevent infinite loops if (language === 'chart') { - return + const chartCode = String(children).replace(/\n$/, '') + return } // Other code blocks diff --git a/memento-note/components/note-chart.tsx b/memento-note/components/note-chart.tsx index 490a8eb..f24f458 100644 --- a/memento-note/components/note-chart.tsx +++ b/memento-note/components/note-chart.tsx @@ -182,7 +182,7 @@ function NoteChart({ type, title, data, colors, showLegend, height = 250 }: Note } default: - return
Type de graphique non supporté: {type}
+ return null } } @@ -246,6 +246,6 @@ export function parseChartFromCode(code: string): NoteChartProps | null { export function NoteChartFromCode({ code }: { code: string }) { const props = useMemo(() => parseChartFromCode(code), [code]) - if (!props) return
Format de graphique invalide
+ if (!props) return null return }