Skip to content

Render log diagrams with @joycostudio/trazo instead of Mermaid#151

Open
justkahdri wants to merge 7 commits into
mainfrom
kahdri/trazo-integration
Open

Render log diagrams with @joycostudio/trazo instead of Mermaid#151
justkahdri wants to merge 7 commits into
mainfrom
kahdri/trazo-integration

Conversation

@justkahdri

@justkahdri justkahdri commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What

Replaces every Mermaid diagram in the two diagram-heavy log articles with the @joycostudio/trazo layout engine, authored as DSL string literals through a new <Diagram> MDX component.

<Diagram> takes the DSL source as a template-literal child, auto-detects the language from the first line (flow / sequence / block / git), and runs the matching pure layout server-side — it's a React Server Component, so the diagrams ship zero client JS (unlike the old <Mermaid> which rendered client-side via the mermaid bundle).

Changes

  • Add @joycostudio/trazo@^0.2.0
  • Add components/flow.tsx exporting <Diagram>, wired into mdx-components.tsx
  • 07-nextjs-promises-ppr.mdx — 7 diagrams: flow charts, 2 sequence diagrams, 2 subgraph flows, and the static-shell layout (now flow TD)
  • 08-webgl-scroll-sync.mdx — 10 diagrams: flow charts with subgraphs, sequence diagrams, multi-line labels

Conventions

  • Flowchart edges use --- (neutral path) and === (colored path) — no arrowheads. Arrowheads appear only on sequence-diagram messages, where direction (->> / -->>) is intrinsic to the diagram.
  • Subgraph containers and sequence lifelines/notes are used directly (no flattening into text prefixes).

Verification

  • tsc --noEmit — clean
  • All 17 DSL blocks parse + lay out standalone (17/17)
  • Both pages render on a dev server: 7 + 10 trazo SVGs, subgraph boxes, lifelines, and note boxes all present; no parse/runtime errors, no error overlay

Follow-ups (out of scope here)

  • components/mermaid.tsx, the mermaid dependency, and remarkMdxMermaid in source.config.ts are now unused in content but left in place — safe to remove in a separate cleanup.
  • components/flow.tsx exports Diagram (not Flow); the filename could be renamed to diagram.tsx later to avoid churn here.

🤖 Generated with Claude Code

Greptile Summary

This PR replaces all Mermaid diagrams in the two diagram-heavy log articles with @joycostudio/trazo DSL via a new <Diagram> RSC, and extends trazo theming to four additional log articles that previously used static images. The <Diagram> component runs layout server-side, ships zero client JS, and wires articleNumber through getMDXComponents for per-article figure numbering.

  • components/flow.tsx: new RSC that auto-detects DSL language, dispatches to the matching trazo parser/layout, and renders either a <Graph> SVG or an ASCII <pre> block inside a styled <figure>.
  • app/styles/theming.css: adds --chart-N-foreground and --trazo-error-foreground tokens across all four themes so saturated trazo nodes pass contrast checks.
  • 17 MDX diagrams across 07-nextjs-promises-ppr.mdx and 08-webgl-scroll-sync.mdx converted from Mermaid fenced blocks to <Diagram> JSX; static images in 11, 12, and 14 also replaced.

Confidence Score: 5/5

Safe to merge; the core component and all diagram conversions are correct. The two style-rule nits are cosmetic and do not affect rendering or behaviour.

The new Diagram RSC is well-structured: server-only, typed, error-throwing on parse failures, and correctly themed. All 17 MDX diagram blocks were converted without data loss. The only findings are em-dash violations in a diagram title and CSS comments, neither of which affects runtime output.

content/logs/12-the-render-pipeline.mdx (em dash in title prop) and app/styles/theming.css (em dashes in comments).

Important Files Changed

Filename Overview
components/flow.tsx New RSC Diagram component wrapping @joycostudio/trazo: detects DSL lang, lays out graph server-side, renders via <Graph> or ASCII <pre>. Error handling, theming, and tag generation look correct.
mdx-components.tsx Adds Diagram to the MDX component map, threaded with articleNumber from the page-level opts. Clean change.
app/(registry)/[[...slug]]/page.tsx Passes { logNumber } as the second arg to getMDXComponents so Diagram receives articleNumber for per-article numbering tags.
content/logs/07-nextjs-promises-ppr.mdx 7 Mermaid blocks replaced with <Diagram> DSL; edge styles and node roles look consistent with stated conventions.
content/logs/08-webgl-scroll-sync.mdx 10 Mermaid blocks replaced with <Diagram> DSL; bidirectional <==> edge on diagram 3 and arrowhead --> on diagram 11 deviate from the stated no-arrowhead convention but appear intentional.
content/logs/11-wtf-is-layout-thrashing.mdx Static image replaced with a trazo flow diagram; cry --> layout edge uses --> to emphasise the forced-reflow cycle back to layout.
content/logs/12-the-render-pipeline.mdx Static image replaced with a trazo diagram; the title prop contains an em dash in violation of the no-em-dash rule.
content/logs/14-phantom-merge-conflicts.mdx Two ascii diagrams and one flow diagram replace bash code blocks; backslashes correctly escaped in template literals.
app/styles/theming.css Adds --chart-N-foreground and --trazo-error-foreground tokens for all four themes; three new CSS comments use em dashes in violation of the house style rule.
package.json Adds @joycostudio/trazo@^0.5.0 dependency.

Reviews (2): Last reviewed commit: "chore: remove stray trazo scratch notes ..." | Re-trigger Greptile

Context used:

  • Rule used - Do not use em dashes (—) in prose, frontmatter des... (source)

@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
joyco-hub Ready Ready Preview, Comment Jul 14, 2026 9:46pm

Comment thread content/logs/07-nextjs-promises-ppr.mdx Outdated
Comment on lines +383 to +384
note over C: Blank screen…
S->>S: await getCart() — 200ms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Em dashes in diagram labels

Diagram labels are rendered as visible SVG text for readers, and the team's style rule prohibits em dashes in any user-visible text, replacing them with a colon, comma, or parentheses instead. Two instances appear here (await getCart() — 200ms, await getFlags() — 150ms), and the pattern repeats elsewhere in this file (Static Shell — built at build time, served from CDN) and in 08-webgl-scroll-sync.mdx (the two edge labels D (delta) — JS animates scrollTop... and D (delta) — JS reads scrollY...).

Rule Used: Do not use em dashes (—) in prose, frontmatter des... (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: content/logs/07-nextjs-promises-ppr.mdx
Line: 383-384

Comment:
**Em dashes in diagram labels**

Diagram labels are rendered as visible SVG text for readers, and the team's style rule prohibits em dashes in any user-visible text, replacing them with a colon, comma, or parentheses instead. Two instances appear here (`await getCart() — 200ms`, `await getFlags() — 150ms`), and the pattern repeats elsewhere in this file (`Static Shell — built at build time, served from CDN`) and in `08-webgl-scroll-sync.mdx` (the two edge labels `D (delta) — JS animates scrollTop...` and `D (delta) — JS reads scrollY...`).

**Rule Used:** Do not use em dashes (—) in prose, frontmatter des... ([source](greptile.json))

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

justkahdri and others added 6 commits July 14, 2026 18:40
Replace every Mermaid diagram in the two log articles with the trazo
layout engine, authored as DSL string literals through a new <Diagram>
MDX component that auto-detects the language (flow / sequence / block /
git) and runs the matching pure layout server-side.

- add @joycostudio/trazo@^0.2.0 and components/flow.tsx (<Diagram>)
- wire <Diagram> into mdx-components
- 07: 2 flow charts, 2 sequence diagrams, 2 subgraph flows, 1 static
  shell flow (was block-beta, now flow TD per review)
- 08: flow charts with subgraphs, sequence diagrams, multi-line labels
- flowchart edges use --- (neutral path) / === (colored path), no
  arrowheads; arrowheads only on sequence messages where direction is
  intrinsic

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
#157)

* Upgrade trazo to 0.4.0 and frame log diagrams full-width

- Bump @joycostudio/trazo 0.3 -> 0.4.0; adopt first-class theming
  (joycoTheme paired via themeFlowOptions/themeGitOptions + <Graph theme>)
- Migrate deprecated `streamed` role to `info` in log diagrams
- Render <Diagram> as a full-width framed figure: hatch-textured canvas,
  accent Badge title + `N{article}-{index}` number tag
- Inject the log number per page via getMDXComponents; number each
  illustration with an explicit `index`
- Pin --trazo-bg to --card so node-box strokes match the frame surface

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(logs): AA-legible trazo diagram labels + keep renderer server-only

Diagram label text now pairs each chart fill with a contrast-checked
foreground (--chart-N-foreground) that trazo's token fallback wires to both
lane slots (lane-2..6 → chart-1..5) and chart-backed roles (success → chart-2,
info → chart-3, warning → chart-4). Fixes the `info` role rendering dark text
on the dark chart-3 fill (~2.2:1), the radio theme's chart-2 mismatch, and the
dead --trazo-streamed-foreground var. Values chosen from real WCAG ratios per
theme; every pair now clears AA except dark chart-1, whose fill lightness sits
in a dead zone no text color can fix.

Also in flow.tsx:
- move <figcaption> to be the first child of <figure> (HTML content model);
  all overlays are absolutely positioned, so no visual change
- derive layout options from graphTheme instead of joycoTheme so both halves
  of the theme come from one object
- import 'server-only' to enforce at build time that the trazo layout engine
  never leaks into a client bundle

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* Update mdx-components.tsx

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Em dashes inside trazo/mermaid diagram DSL labels swapped for `:` or
parenthesised clauses so labels read cleanly in the rendered diagrams.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ming

The trazo git graph rendered branches in near-identical blues and never
showed the commit letters (A, B, S, …) the prose refers to, which made
the phantom-merge-conflicts illustrations confusing. Restore them as
plain-text ASCII graphs (letters + branch lanes) via a new `ascii` mode
on <Diagram> that keeps the framed, numbered illustration wrapper.

Also improves the trazo git DSL path (still available for future use):
horizontal orientation (git-log-style left→right timeline), labels above
the lane, and a contrasting lane pair so branches are distinguishable.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Additive release (new `textCase` theme knob + inline `code` chips in
flow-node labels); non-breaking, no code changes required.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@justkahdri justkahdri force-pushed the kahdri/trazo-integration branch from f3c6cb2 to ad28c3a Compare July 14, 2026 21:43
Leftover from an earlier trazo-exploration session (feature-request notes
and a git-DSL test scratch); not part of the app.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@justkahdri justkahdri marked this pull request as ready for review July 14, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant