Repository navigation
perf(vue): keep the parser out of defineMarkdownDocumentComponent - #632
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Architecture Data flow No data-flow sequence changed in this PR. Review ✨ Nothing flagged · reviewed Tip Set 🪧 More tips
Thanks for using PR Lens! It's free for OSS. If it helped, a star helps other teams find it. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
comark
@comark/angular
@comark/ansi
@comark/html
@comark/nuxt
@comark/react
@comark/svelte
@comark/vue
commit: |
Merging this PR will not alter performance1 warning
Comparing |
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.
✅ Bundle snapshot updatedCommitted 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 Produced by this run. |
What
defineMarkdownDocumentComponentmoves from the@comark/vueindex 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 usesdefineMarkdownComponentanywhere, even on a lazy page, the bundler puts the parser in a chunk shared with every page that importsdefineMarkdownDocumentComponentfrom 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-importsparseMarkdownfrom@comark/vue/parseonly where it's used, and #600 moved the<MarkdownDocument>auto-import off the index, butdefineMarkdownDocumentComponentstill came from it.Evidence
Benchmark:
examples/1.frameworks/nuxtat 544289d, with two scratch changes that are not part of this PR:Method:
nuxt buildwith@comark/vuebuilt from each side, then the gzip size of everymodulepreloadand module script in the prerendered HTML. Sizes are deterministic. One build per side:main/blog/hello-world(renders a parsed post)markdown-exit,js-yaml, andMarkdown.js/chat(usesdefineMarkdownComponent)Without the
/chatpage,mainalready keeps the parser off/blog/hello-world(146.3 kB). Only adefineMarkdownComponentthat is actually used triggers the problem.Docus running Nuxt Content v4
Before
After
Notes
import { defineMarkdownDocumentComponent } from '@comark/vue'still works. The index now also exports theDefineMarkdownDocumentOptionstype.@comark/vueitself and needs a one-line follow-up to get the Docus saving.defineMarkdownDocumentComponenton one page anddefineMarkdownComponenton another, the first page loads 74.0 kB gzip including the parser, against 4.1 kB without it. The fix is the same move intocomponents/MarkdownDocument.tsx.Markdown,defineMarkdownComponentorprovideMarkdownmakes everyMarkdownDocumentpage load the parser: 76.4 kB gzip, against 6.5 kB when no page usesMarkdown. 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