Conversation
|
Preview (prod) → https://216-prod.rucq-ui-preview.trapti.tech/ |
📝 WalkthroughWalkthroughMarkdownItのインスタンス生成をコンポーネントから専用ユーティリティに抽出し、DOMPurifyのサニテーション処理フローをHTML文字列ベースからDOM直接返却に変更。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Comment |
There was a problem hiding this comment.
Pull request overview
MarkdownPreview.vue で、Markdown → HTML 生成後に DOMPurify のサニタイズ結果(HTML文字列)を再度 DOMParser でパースしていた処理を、DOMPurify から DOM を直接受け取る形に変えて二重パースを解消する PR です。あわせて MarkdownIt インスタンスを utils に切り出し、コンポーネント毎の生成を避けることで再利用可能にしています。
Changes:
- DOMPurify のサニタイズ結果を文字列ではなく DOM として扱い、見出し抽出時の再パースを削除
- MarkdownIt インスタンスを
src/utils/markdown.tsに移動して共有化
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/utils/markdown.ts | 再利用用の MarkdownIt インスタンスを定義・export |
| src/components/markdown/MarkdownPreview.vue | DOMPurify の RETURN_DOM を使って DOM から直接見出し抽出し、HTML 出力もその DOM 由来に変更 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const level = parseInt(heading.tagName.charAt(1)) | ||
| const id = `heading-${idCounter++}` | ||
| const text = heading.textContent ?? '' | ||
| const text = heading.textContent |
There was a problem hiding this comment.
HeadingInfo.text is typed as string, but heading.textContent is string | null under strict: true. This will either fail type-checking or force downstream handling of null. Consider using a nullish fallback (e.g., heading.textContent ?? '') or updating HeadingInfo.text to allow null if that's intended.
| const text = heading.textContent | |
| const text = heading.textContent ?? '' |
There was a problem hiding this comment.
strict: true の場合にも heading.textContent は string と型推論され、null にはなりえません。heading 自体が Element として型推論されているからです
緊急ではありません あとブランチ名はうそです
MarkdownPreview.vue において DOMPurify.sanitize の結果(HTML テキスト)を再度パースして見出しを見つける無駄な処理が走っていたので、DOMPurify から DOM を返させて見出し探しに利用することでパースを 1 回にします
また、大した効果はないと思うけれど MarkdownIt インスタンスを utils/markdown.ts に引っ越してコンポーネント毎に作成されないようにすることでメモリ効率を少しだけ上げた(かもしれない)
Summary by CodeRabbit
リリースノート