Split the mermaid machinery out of markdown.tsx - #984
Merged
Conversation
markdown.tsx was 489 lines, of which ~295 were mermaid rendering that only one of its four Markdown variants uses. Moved whole, unchanged: - markdown-mermaid-theme.ts (109) — MermaidRenderTheme, the hsl token helpers, and the useMermaidTheme hook. - markdown-mermaid.tsx (194) — the module-level render queue, mermaid init/render helpers, and MermaidBlock. - markdown.tsx (184) — getCodeBlock and the four Markdown* variants. Pure restructuring: no declaration was reshaped, no hook changed owner, and effect registration order is unchanged.
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.
What
apps/web/src/components/ui/markdown.tsxwas 489 lines. Roughly 295 of those were mermaid rendering machinery that only one of the file's four Markdown variants (MarkdownDefault) ever touches — every consumer of thepinandcaptionvariants was loading it for nothing.Split into three files, each declaration moved whole and unchanged:
markdown-mermaid-theme.tsMermaidRenderTheme,hslToken/parseHslChannels/lightnessFromHsl,useMermaidThememarkdown-mermaid.tsxgetMermaidConfig/getMermaid/ensureMermaidInitialized/renderMermaidDiagram,MermaidBlockmarkdown.tsxgetCodeBlock,MarkdownProps,Markdown,MarkdownCaption,MarkdownPin,MarkdownDefaultImport direction is a straight chain with no cycle:
markdown.tsx→markdown-mermaid.tsx→markdown-mermaid-theme.ts(andmarkdown.tsx→ the theme file directly for the hook). The only exported symbol outside the family is stillMarkdown, so none of the 10 consumers changed.Why it was a candidate
Queued by the previous componentizer run. Over 300 lines, and mixed concerns — CSS-variable-to-mermaid theme derivation, a module-level async render queue, and three purely presentational markdown wrappers all in one file.
components/ui/markdown.tsxis shared UI with 10 consumer files, so the context saving is broad rather than feature-local.Behaviour
Purely structural. No declaration was reshaped, no hook changed owner (
useMermaidThemeis still the single hook call at the top ofMarkdownDefault;MermaidBlock's state and async render effect stayed insideMermaidBlock), and effect registration order is unchanged.Validation
pnpm run finalize:web— type check + production build pass.pnpm run test:e2e— 181 passed, 12 skipped (the skipped ones are theterminal-livesuite, skipped by default). This includes the two existing mermaid E2E tests that render a diagram in the media lightbox and exercise both copy buttons.data-themelive and confirmed the extracteduseMermaidThemeMutationObserver still fires and re-renders the diagram.Next run
Queued:
apps/web/src/components/app/persona-launcher.tsx(554 lines, measured this run) — the largest backlog entry with a clear seam, and now the second-largest non-test component in the app.