fix(mermaid): use stable id to prevent re-mount flicker on streaming render #1947 - #2020
fix(mermaid): use stable id to prevent re-mount flicker on streaming render #1947#2020LLL-2005-ux wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughMermaid 组件使用 ChangesMermaid ID 稳定化
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
8601981 to
e888534
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/x/components/mermaid/Mermaid.tsx (1)
67-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win补充稳定 ID 的回归断言。
packages/x/components/mermaid/__tests__/index.test.tsx:901-914只验证连续rerender后mockRender被调用。它没有验证children变化后传给mermaid.render的第一个参数保持不变。请补充该断言,避免后续改动重新引入流式渲染抖动而测试仍然通过。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/x/components/mermaid/Mermaid.tsx` around lines 67 - 72, 在 Mermaid 组件测试中补充 children 变化后的稳定 ID 回归断言:围绕 mermaid.render 的 mockRender 调用,先记录初次渲染传入的第一个参数,再 rerender 不同 children 并断言该参数保持不变;保留现有连续 rerender 调用断言。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/x/components/mermaid/Mermaid.tsx`:
- Around line 67-72: 在 Mermaid 组件测试中补充 children 变化后的稳定 ID 回归断言:围绕 mermaid.render
的 mockRender 调用,先记录初次渲染传入的第一个参数,再 rerender 不同 children 并断言该参数保持不变;保留现有连续
rerender 调用断言。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c65bd02-e829-446e-a2a0-cc4c3c51def3
📒 Files selected for processing (1)
packages/x/components/mermaid/Mermaid.tsx
close #1947
问题
Mermaid.tsx 第 67 行
const id = \mermaid-${uuid++}-${children?.length||0}``,每次渲染都生成新 id(uuid++ 且流式时 children.length 变化),导致 mermaid
生成的 DOM 反复创建/销毁,引起页面抖动。
修复
使用
useRef缓存 id,组件生命周期内只生成一次:流式渲染时 children 变化不会改变 id,DOM 不再反复 mount/unmount,
解决关联抖动问题 (#1742)。
改动文件
packages/x/components/mermaid/Mermaid.tsx验证
Summary by CodeRabbit