From da3033db2167ee63c658714fe03f830ed18e465b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Fri, 4 Sep 2026 12:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=81=8A=E5=A4=A9=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=8A=82=E7=82=B9=E5=B1=9E=E6=80=A7=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 从 react-markdown code 组件属性中剔除 node 元数据。 新增回归测试,确保渲染后的代码节点不输出 node 属性。 --- .../src/components/ChatMarkdownMessage/index.tsx | 2 +- .../tests/ChatMarkdownMessage.test.tsx | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx b/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx index 139b15567..8e2545024 100644 --- a/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx +++ b/apps/ai-game-creator-shell/src/components/ChatMarkdownMessage/index.tsx @@ -79,7 +79,7 @@ const markdownComponents: Components = { {children} ), - code: ({ className, children, ...props }) => { + code: ({ className, children, node: _node, ...props }) => { const isBlock = Boolean(className?.includes('language-')); return isBlock ? ( diff --git a/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx b/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx index ae877f8db..1c293be74 100644 --- a/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx +++ b/apps/ai-game-creator-shell/tests/ChatMarkdownMessage.test.tsx @@ -21,6 +21,19 @@ describe('ChatMarkdownMessage', () => { ); }); + it('不会把 react-markdown 的 node 元数据泄漏到代码节点', () => { + const { container } = render( + , + ); + + expect( + container.querySelector('pre code')?.getAttribute('node'), + ).toBeNull(); + }); + it('保留流式 assistant 文本并标记 streaming 状态', () => { const { container } = render(