perf(ui): cache Mermaid renders across remounts - #4977
Conversation
Reuse sanitized Mermaid SVG templates by renderer version, theme, and source while bounding cache memory and preserving instance-local SVG references. Coalesce identical in-flight renders and cover remounts, theme changes, cancellation, ID isolation, and LRU eviction. Fixes apache#4976 Generated-by: Codex
Astro-Han
left a comment
There was a problem hiding this comment.
Thanks for addressing the repeat-render path in #4976. Reviewed fc4c96b6 with two independent reviewer lanes and primary-agent reconciliation. The bounded cache, coalescing and cancellation behavior fit the problem and do not introduce another authority. One P2 remains in SVG selector preservation, detailed inline.
The four cache/component cases passed in an exact-head source-loader probe. An independent probe using real Mermaid 11.17.2 under a DOM polyfill confirmed the supported themeCSS output involved in the finding; a primary-agent probe of the exact namespace implementation confirmed the selector stops matching after rewriting. The React/Mermaid dependencies used match the PR lockfile. These are source/DOM probes, not a fresh workspace build or real Desktop renderer acceptance. Current CI is green.
Please fix the selector contract and verify actual light/dark rendering of repeated flowchart/sequence diagrams, including the custom themeCSS case, before UI approval. No broader cache framework or unrelated restructuring is needed.
AI-assisted review with independent reviewers and primary-agent verification.
中文
感谢修复 #4976 的重复渲染。两个 reviewer 独立检查并经主审复核 fc4c96b;有界缓存、合并并发和取消逻辑符合问题,没有新增权威。仍有一项 P2:SVG 选择器语义未完整保留,见行内。
四个缓存/组件用例通过 exact-head 源码加载验证;真实 Mermaid 11.17.2 配合 DOM polyfill 复现了相关 themeCSS 输出,主审用当前 namespace 源码确认重写后选择器失配。React/Mermaid 版本与 PR lock 一致。这不是重新构建 workspace,也不代表真实 Desktop renderer 验收;当前 CI 绿色。
请修复选择器契约,并验收实际 light/dark 下重复 flowchart/sequence 及自定义 themeCSS。无需新增缓存框架或扩大重构。此次为 AI 辅助评审,经独立 reviewer 与主审复核。
Generated-by: Codex
Astro-Han
left a comment
There was a problem hiding this comment.
Thanks for the fix. Re-reviewed abc1aadf0: the previous attribute-selector finding is resolved. Independent real-Mermaid checks and an exact-source Chromium harness confirmed that two instances and cached remounts retain the expected computed opacity, SVG IDs remain disjoint, and light/dark rendering stays separate while repeated instances reuse the cache. No remaining P0–P2 findings.
The six cache tests also pass through the exact-head source loader. The added tests reuse the existing DOM fixture and protect real rendering behavior; no additional abstraction or test reduction is requested. Current-head CI is green. These focused probes are not a fresh workspace build or a full Desktop-shell run.
AI-assisted independent reviewers and primary source/probe reconciliation.
中文
感谢修复。abc1aadf0 已解决旧属性选择器问题。真实 Mermaid 检查和 exact-source Chromium 验证确认:两个实例及缓存重挂载的计算 opacity 正确,SVG ID 无交集,light/dark 分别缓存,重复实例复用缓存。无剩余 P0–P2。
六项缓存测试也通过;新增测试复用现有 DOM 夹具并保护真实渲染行为,不要求额外抽象或为行数删测试。当前 CI 绿色。这些定向探针不替代全新 workspace 构建或完整 Desktop shell 验收。经 AI 独立评审与主审源码/探针核对。
…esign reverted Codex's pass against upstream 93a8dd7, reviewed file by file (docs/enterprise/phase-reports/core-dialogue-regressions.md, "协调者审查"): Kept: local message delivery status over the `sessionLocal` outbox (upstream apache#4956, previously deferred — pending/sending/unknown rows with remove/check actions, locally pending Sessions observed without a Host round trip); revision cancel/uncertain lifecycle in `revision-actions.ts` (retry reuses the copy and message id, canonical proof settles it); queue edits pinned to their starting revision; optimistic and Host-queued rows merged by id and rendered outside durable turns (no synthetic Turn, no regenerate/branch on a pending row); Markdown escapes raw HTML by default, routes `maka:` links through `MakaUriContext`, allows mail links, loads session attachment images, and renders Mermaid with upstream apache#4977's strict mode, budget, cache and id isolation; Alt+Enter line break; copy takes the final answer; steering rows keep attachments/directories/references. Reverted: replacing the transcript consumer on send. The navigation intent lives on main's per-Session replica, so a fresh consumer still followed history and a send from history never reached the tail; upstream's followTail navigation ordered ahead of the send is restored, and the four tests for the reverted design are dropped. Fixed: 12 unformatted files, a test cast, a stale architecture ledger, the stale `mermaid` knip ignore, and the composer's "configure a model" hint that showed while a target's connections were still loading. Verification after review: static gates and knip; renderer-state 198; desktop dist 1469; renderer smoke 43 + core-dialogue smoke; prompts smoke; e2e 35 (one scroll-cost timeout under load, 6/6 on rerun); real-window smoke. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary
Cache sanitized Mermaid render templates by Mermaid version, theme, and source so unchanged diagrams do not repeat parse, layout, render, and sanitization work after remounts. The cache is bounded to 24 entries and 4 MiB, coalesces identical in-flight renders, excludes failures, and gives every mounted SVG instance its own rewritten ID namespace.
Fixes #4976
Verification
npm run lintnpm run format:checknpm run buildnpm run typechecknpm --workspace @maka/ui run test:dist(407 passed)npx knip --workspace apps/desktopnpx knip --workspace packages/uiNo screenshot is included because this is a performance-only change with no intended visual difference; the component regressions assert cache reuse, theme isolation, in-flight coalescing, cancellation behavior, SVG ID/reference isolation, and LRU eviction.
Review focus
Mermaid sequence diagrams emit fixed IDs such as
actor1androot-1. Cached templates therefore namespace every internal ID and rewrite local URL, ARIA, href, animation, and CSS references before per-instance namespace substitution.AI use
Select exactly one:
Tool(s) and scope: Codex diagnosed the repeated-render path, implemented the bounded cache and SVG ID isolation, and authored the regression tests under human direction and review.
Checklist
Does this PR entail a change in behavior?
Automated submission by Codex on behalf of @liuxiaocs7.