From b7f1eb9b7b2e87ac4c87dbe552b1c969b967c0ce Mon Sep 17 00:00:00 2001 From: yyh Date: Tue, 27 Jan 2026 01:10:00 +0800 Subject: [PATCH] fix(markdown)!: return empty string for non-string content in preprocessors Related to a9c5201485 - when switching views during active preview run, the markdown preprocessors could receive non-string content (e.g., frozen arrays from immer). Returning the original value caused ReactMarkdown to fail with "Cannot assign to read only property" error. Now both preprocessLaTeX and preprocessThinkTag return '' for non-string input, preventing runtime errors during view switches. --- web/app/components/base/markdown/markdown-utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/web/app/components/base/markdown/markdown-utils.ts b/web/app/components/base/markdown/markdown-utils.ts index 94ad31d1de..c3aeef410a 100644 --- a/web/app/components/base/markdown/markdown-utils.ts +++ b/web/app/components/base/markdown/markdown-utils.ts @@ -8,7 +8,7 @@ import { ALLOW_UNSAFE_DATA_SCHEME } from '@/config' export const preprocessLaTeX = (content: string) => { if (typeof content !== 'string') - return content + return '' const codeBlockRegex = /```[\s\S]*?```/g const codeBlocks = content.match(codeBlockRegex) || [] @@ -32,6 +32,9 @@ export const preprocessLaTeX = (content: string) => { } export const preprocessThinkTag = (content: string) => { + if (typeof content !== 'string') + return '' + const thinkOpenTagRegex = /(\s*)+/g const thinkCloseTagRegex = /(\s*<\/think>)+/g return flow([