Skip to content

perf: skip micromark + innerHTML for plain text without markdown syntax (#145)#146

Merged
rohal12 merged 8 commits into
mainfrom
fix/published-types-sync
Mar 28, 2026
Merged

perf: skip micromark + innerHTML for plain text without markdown syntax (#145)#146
rohal12 merged 8 commits into
mainfrom
fix/published-types-sync

Conversation

@rohal12

@rohal12 rohal12 commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Plain text fast path in renderNodes: After building the combined string, detect when text contains no markdown-triggering characters and build vnodes directly — bypassing both micromark and innerHTML. Eliminates ~655 innerHTML calls on plain UI text like "ALMA", "▸ Crew", "Activate" that pass through the full pipeline only to produce the same text they started with.
  • Inline elements fix: Added INLINE_ELEMENTS set and inline option to markdownToHtml to disable block-level markdown constructs (lists, headings, blockquotes) inside inline HTML elements like <span>.
  • Projected impact: Reduces click duration from 288ms to ~80-100ms for ALMA-like UI passages with nested HTML + {for} loops.

Detection

Conservative regex /[*_#|~[>\-+=]|![|\d+./covers all CommonMark + GFM syntax characters. Any false positive (text contains-` but not as a list item) harmlessly falls through to the existing micromark path. Zero risk to markdown rendering.

Test plan

  • 24 correctness baseline tests (plain text, variables, Unicode, punctuation, non-nobr <p> wrapping)
  • 13 fallthrough tests (all markdown syntax characters trigger full pipeline)
  • Benchmark: ALMA-like UI ~5ms/render, 100 HTML elements ~3ms/render
  • Full suite: 1121/1121 tests pass
  • tsc --noEmit clean

Closes #145

🤖 Generated with Claude Code

clem and others added 7 commits March 28, 2026 01:57
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…path (#145)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Inline elements like <span>, <em>, <a> should not produce block-level
markdown constructs (lists, headings, blockquotes). Added INLINE_ELEMENTS
set and inline option to markdownToHtml to disable these constructs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
#145)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
These were missing from MARKDOWN_SYNTAX_RE: + is a CommonMark list
marker (like - and *), = is used for setext heading underlines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Release preview: merging this PR will publish v0.43.4 (patch bump from v0.43.3)

@github-actions

github-actions Bot commented Mar 28, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 77.56% 2855 / 3681
🔵 Statements 76.54% 3116 / 4071
🔵 Functions 69.04% 513 / 743
🔵 Branches 73.64% 1559 / 2117
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/markup/markdown.ts 100% 100% 100% 100%
src/markup/render.tsx 91.11% 82.5% 100% 94.21% 87, 165, 230-236, 251-252, 263, 284, 285, 286, 290-291
Generated in workflow #224 for commit 3d0c96c by the Vitest Coverage Report Action

@rohal12 rohal12 merged commit 3bb9f61 into main Mar 28, 2026
5 checks passed
@rohal12 rohal12 deleted the fix/published-types-sync branch March 28, 2026 02:15
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.

Performance: skip micromark + innerHTML for plain text without markdown syntax

1 participant