Skip to content

perf(vue): keep the parser out of defineMarkdownDocumentComponent - #632

Merged
farnabaz merged 3 commits into
mainfrom
perf/vue-document-without-parser
Nov 26, 2026
Merged

farnabaz merged 3 commits into
mainfrom
perf/vue-document-without-parser

Conversation

@larbish

@larbish larbish commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Written by an AI agent on behalf of @larbish, who reviewed it before opening.

What

defineMarkdownDocumentComponent moves from the @comark/vue index into @comark/vue/components/MarkdownDocument, next to <MarkdownDocument>. The index still re-exports it, and the Nuxt module now auto-imports it from that entry.

Why

The index also holds defineMarkdownComponent, which loads <Markdown> and the parser, so when an app uses defineMarkdownComponent anywhere, even on a lazy page, the bundler puts the parser in a chunk shared with every page that imports defineMarkdownDocumentComponent from the index. We found it on Docus, where the docs pages preloaded a 79 kB gzip chunk that was mostly the parser. This follows @atinux's work to keep the parser out of bundles that don't use it: #576 auto-imports parseMarkdown from @comark/vue/parse only where it's used, and #600 moved the <MarkdownDocument> auto-import off the index, but defineMarkdownDocumentComponent still came from it.

Evidence

Benchmark: examples/1.frameworks/nuxt at 544289d, with two scratch changes that are not part of this PR:

// app/components/BlogDocument.ts, used by pages/blog/[slug].vue
export default defineMarkdownDocumentComponent({ name: 'BlogDocument' })

// app/components/ChatMessage.ts, used by pages/chat.vue
export default defineMarkdownComponent({ name: 'ChatMessage' })

Method: nuxt build with @comark/vue built from each side, then the gzip size of every modulepreload and module script in the prerendered HTML. Sizes are deterministic. One build per side:

Page main This PR
/blog/hello-world (renders a parsed post) 216.1 kB, 33 files, including a 73.1 kB chunk with markdown-exit, js-yaml, and Markdown.js 146.4 kB, 32 files, no parser
/chat (uses defineMarkdownComponent) 183.8 kB 184.4 kB, still loads the parser

Without the /chat page, main already keeps the parser off /blog/hello-world (146.3 kB). Only a defineMarkdownComponent that is actually used triggers the problem.

Docus running Nuxt Content v4

Before

CleanShot 2026-11-26 at 11 37 25@2x

After

CleanShot 2026-11-26 at 11 47 27@2x

Notes

  • Not breaking: import { defineMarkdownDocumentComponent } from '@comark/vue' still works. The index now also exports the DefineMarkdownDocumentOptions type.
  • Nuxt Content imports @comark/vue itself and needs a one-line follow-up to get the Docus saving.
  • Follow-ups for the other renderers. I checked them with a Vite 8 scratch app: one lazy page renders a parsed document, another uses the parser-backed component.
    • React has the same bug. With defineMarkdownDocumentComponent on one page and defineMarkdownComponent on another, the first page loads 74.0 kB gzip including the parser, against 4.1 kB without it. The fix is the same move into components/MarkdownDocument.tsx.
    • Angular ships as one FESM file, so any page using Markdown, defineMarkdownComponent or provideMarkdown makes every MarkdownDocument page load the parser: 76.4 kB gzip, against 6.5 kB when no page uses Markdown. That was measured with Angular's linker and production optimizations applied. Fixing it needs a secondary ng-packagr entry point.

ELI5

Comark has two kinds of renderers: one reads Markdown text and needs a big parser, the other shows content that was already read. Both helpers lived in the same file, so when an app used the first one anywhere, pages that only needed the second one downloaded the parser too. This PR moves the second helper next to the component it uses, so those pages skip the parser.

🤖 Generated with Amp, reviewed by @larbish before opening.

Summary by CodeRabbit

  • New Features
    • Added helpers for creating customized Markdown and Markdown Document components.
    • Configure components, transforms, plugins, and wrapper classes, and extend existing components. Instance-provided component mappings take precedence over configured mappings; configured and instance transforms are combined.
    • Nuxt auto-imports the helpers from their respective component entry points.
  • Documentation
    • Updated Nuxt auto-import documentation to reflect the helpers’ component entry points.

@larbish
larbish requested a review from farnabaz as a code owner November 26, 2026 10:14
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
comark Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-binding Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-json-render Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-nextjs Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-nuxt Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-svelte Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-sveltekit Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-twoslash Ready Ready Preview Nov 26, 2026 1:20pm UTC
comark-vue Ready Ready Preview Nov 26, 2026 1:20pm UTC

Request Review

@coldtea-pr-lens

coldtea-pr-lens Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
  • Redraw · drawn at 0cf98c1, the branch has moved on

Architecture

Walkthrough of Keep parser out of document helper bundles, in three steps

Read this PR faster


Data flow

No data-flow sequence changed in this PR.


Review

✨ Nothing flagged · reviewed 0cf98c1


Tip

Set github.draw: on-demand in .github/pr-lens.yml and PR Lens stops drawing pull requests on its own. Comment @pr-lens draw on a pull request when you want that one drawn

🪧 More tips
  • Run npx skills add coldteadotai/pr-lens, then tell your coding agent: "Diagram the change you just made with PR Lens and attach it to the pull request."
  • Run npx @coldtea/pr-lens-cli analyze --base origin/main on a branch, then npx @coldtea/pr-lens-cli render .pr-lens/graph.json. Same lenses, your own model key, before the pull request exists
  • Click the link under each diagram to open it on a canvas you can zoom, pan and step through
  • The diagrams are links. Click one to open it on the canvas, then press W or click play to walk through the change
  • Open a diagram on the canvas, then press W or click play to walk through the change one step at a time
  • The CLI's render reads .github/pr-lens.yml and applies your renames, exclusions and lane pins at draw time
  • Set github.comment.collapsed: true in .github/pr-lens.yml to fold the comment behind one View architecture… row. Drawing still runs as before
  • Add .github/workflows/pr-lens.yml with coldteadotai/pr-lens/packages/action@v0 and your model provider's key as its api-key to run PR Lens from your own CI. Any /chat/completions endpoint works
  • After a push, tick Redraw to draw the latest commit
  • Switch GitHub to dark mode and the diagrams follow. The moving dots are this pull request's data in motion
  • Set github.description: false in .github/pr-lens.yml to stop PR Lens adding buttons to your PR descriptions

Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it.  Star PR Lens on GitHub

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PR adds component factory helpers for Markdown and MarkdownDocument. The package index re-exports the helpers, and Nuxt auto-imports them from their component entry points. Tests and documentation reflect the updated import paths.

Changes: Markdown component factories and Nuxt imports

Layer / File(s) Summary
Define and export component factories
packages/comark-vue/src/components/Markdown.ts, packages/comark-vue/src/components/MarkdownDocument.ts, packages/comark-vue/src/index.ts, test/bundle.test.ts
The component modules add factory options and helpers. The Markdown factory merges configured options, plugins, components, and transforms with instance props. The MarkdownDocument factory merges component mappings and transforms. Both forward props, the configured class, and the default slot to the selected component. The package index re-exports the helpers, options, components, and props types. The published-size snapshot changes from 62.6k to 62.5k; the file count remains 91.
Register and verify Nuxt auto-imports
packages/comark-vue/src/nuxt.ts, packages/comark-vue/test/nuxt.test.ts, AGENTS.md
Nuxt resolves each factory from its component entry point. Tests verify the registered source paths and that the helper exports match the package index. Documentation records the component paths.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Refactor

Possibly related PRs

Merge Risk: Minimal · up to 829c4

This change moves the Markdown define helpers into their component entry points. The package index still re-exports them, so existing imports keep working. No concrete defect was found, and the remaining risk is the usual check that the package-size snapshot passes in CI.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names a performance change (keeping the parser out of defineMarkdownDocumentComponent) that matches the main change: defineMarkdownDocumentComponent moves into the MarkdownDocument component…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names a performance change (keeping the parser out of defineMarkdownDocumentComponent) that matches the main change: defineMarkdownDocumentComponent moves into the MarkdownDocument component entry, and the Nuxt module auto-imports it from there. The title is specific, and the changeset includes the matching move, export, and Nuxt import updates.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5d6540d7-05ca-47d0-b527-812ed6d1568f
Commits

Reviewing files that changed from the base of the PR and between cd47a8a and 829c4e1.

Files selected for processing: 1

  • test/bundle.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@632

@comark/angular

npm i https://pkg.pr.new/@comark/angular@632

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@632

@comark/html

npm i https://pkg.pr.new/@comark/html@632

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@632

@comark/react

npm i https://pkg.pr.new/@comark/react@632

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@632

@comark/vue

npm i https://pkg.pr.new/@comark/vue@632

commit: 829c4e1

@larbish
larbish requested a review from atinux November 26, 2026 10:19
@codspeed

codspeed Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 48 untouched benchmarks


Comparing perf/vue-document-without-parser (829c4e1) with main (509cac5)

Open in CodSpeed

Moves `defineMarkdownComponent` and its (now exported) `DefineMarkdownComponentOptions` into `src/components/Markdown.ts`, so `src/index.ts` only holds re-exports. The Nuxt module auto-imports `defineMarkdownComponent` from `@comark/vue/components/Markdown`. Tests and AGENTS.md are updated to match.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ Bundle snapshot updated

Committed the new snapshot as 829c4e1, verified by re-running the bundle check against it.

GitHub suppresses the events a workflow commit would normally raise, so the ci check above may
still show the earlier failure. Re-run it to refresh the status — the snapshot itself is confirmed green.

Produced by this run.

@farnabaz farnabaz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, Thanks

@farnabaz
farnabaz merged commit ff4661d into main Nov 26, 2026
15 checks passed
@farnabaz
farnabaz deleted the perf/vue-document-without-parser branch November 26, 2026 13:29
@github-actions github-actions Bot mentioned this pull request Nov 26, 2026

This branch was successfully deployed

8 active deployments
Preview – comark-nuxt — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-sveltekit — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-json-render — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-binding — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-twoslash — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-vue — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-nextjs — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
Preview – comark-svelte — 829c4e16 Deployed Nov 26, 2026 by vercel[bot]
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.

2 participants