Repository navigation
feat(clients): render Mermaid diagrams as text off the UI thread - #2
Merged
Merged
Conversation
Keep the text renderer and its parsers in a dependency-free workspace package so layout can run independently of the client or server. Expose plain ASCII and Unicode output and fix invalid coordinates when chains exceed 25 nodes.
Show supported Mermaid fences as selectable text diagrams with source switching and copying. Keep rendering local to each client and preserve source when a diagram exceeds the renderer's limits or is unsupported. A browser worker and native Worklets runtime share bounded admission, deduplication, and caching. Native Bundle Mode requires Metro patches and ESM resolution for workspace packages under inline imports.
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
Keep complete statements, updated labels, bottom-to-top text, and initial sequence notes in rendered diagrams. Size subgraph titles to fit and fall back to source when spacing cannot preserve them. Remove unused terminal coloring and its parallel canvases. Reuse the shared clipboard hook so diagram copying works over remote HTTP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mermaid fences currently appear as source in chat and Markdown previews. Supported fences now render as selectable text diagrams, with source switching and copying. Unsupported, invalid, or oversized inputs keep their source.
The renderer is vendored into a standalone workspace package with no runtime dependencies. Web and desktop lazily render visible, closed fences in a browser worker. Mobile renders completed messages in a dedicated Worklets runtime. Its build produces one self-contained worklet, using the existing Expo/Babel setup. Native output uses ASCII borders so Android font fallback cannot misalign Unicode box characters. The text renderer omits terminal coloring and its extra canvases.
The clients share serialized admission, source deduplication, and a bounded cache. Input, graph, allocation, pathfinding, and cooperative time limits bound rendering work. Unsupported syntax and titles that cannot fit their layout retain source. Browser workers have startup and execution deadlines with replacement after failure. Native Worklets has no termination API and relies on the renderer's deterministic bounds and cooperative deadline. The server still delivers the original Markdown.
Implementation and submission were requested by the repository maintainer in the originating thread. This uses the shared Markdown paths for chat and previews, is provider-independent, and requires no server contract or connection-mode changes. The Android chat prerequisite in #6 has merged; this PR targets
main.Verification: 272 focused tests passed, including 100 golden fixtures, parser and drawing fidelity, deep-chain layout, bounds, queue/cache behavior, browser recovery, clipboard fallback, native representation switching, and native packaging. Packaging tests execute the actual serialized worklet for both platform Babel configurations, check parity for six diagram types, and exercise rejected inputs and deadlines. Scoped typechecks, targeted lint, and the mobile dependency check passed. The web production build passed with a separate 77,427-byte worker (23,651 bytes gzip). Production exports for iOS and Android produced Hermes bytecode.
An integrated web pass verified rendering, source switching, copying without the Clipboard API, and source fallback. The actual browser worker passed the statement, label, bottom-to-top, sequence-note, and long-title regressions. An installed Android API 35 development client verified cold startup, pairing with isolated server state, flowchart and sequence rendering, horizontal panning, source switching after panning, copy feedback, fallback-source copy/paste, and light/dark appearance. A renderer source edit appeared in the native background runtime through Fast Refresh; reverting it restored the original diagram. Native verification caught and fixed the startup integration, Android copy icon, scroll reset, and border alignment issues.
iOS simulator execution remains unverified. The installed Xcode 26.3 fails while compiling ExpoModulesJSI before application code runs. Expo documents this toolchain incompatibility; the simulator pass needs a newer Xcode. Packaged Electron and Android release APK execution were not tested. Landing checks exposed stale test fixtures left by the existing app-identity change; their WSL paths, branch prefixes, and release URLs now match production. The four affected test files pass locally (108 tests), and their 13 Linux-only cases pass in CI. CI passes the full test suite, lint, typecheck, build, Rust, and release smoke checks.
Screenshots
Web: rendered sequence diagram and unsupported-input fallback.
Web before: Mermaid source
Android: selectable ASCII diagrams with horizontal scrolling.
Android source view
Recordings: web switching and copying, Android switching and copying.
Model: GPT-6-Astra. Harness: Codex.