mirror of
https://github.com/langgenius/dify.git
synced 2026-01-30 00:36:12 +08:00
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.
This commit is contained in:
@ -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 = /(<think>\s*)+/g
|
||||
const thinkCloseTagRegex = /(\s*<\/think>)+/g
|
||||
return flow([
|
||||
|
||||
Reference in New Issue
Block a user