Skip to content

fix(yaml): resolve empty props blocks instead of throwing - #324

Merged
farnabaz merged 4 commits into
comarkdown:mainfrom
adamdehaven:fix/issue-319-empty-yaml-props-throw-error
Aug 3, 2026
Merged

fix(yaml): resolve empty props blocks instead of throwing#324
farnabaz merged 4 commits into
comarkdown:mainfrom
adamdehaven:fix/issue-319-empty-yaml-props-throw-error

Conversation

@adamdehaven

Copy link
Copy Markdown
Contributor

🔗 Linked issue

#319

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Empty, whitespace-only, or comment-only YAML props/frontmatter blocks (e.g. ::hero\n---\n---\ncontent\n::) threw YAMLException: expected a document, but the input is empty because parseYaml() used js-yaml's load(), which throws whenever it finds zero documents.

parseYaml() now uses loadAll() and branches on documents.length: zero documents resolves to undefined (treated like an omitted block), one document parses normally, and more than one still throws — preserving load()'s original single-document guard. This avoids matching on the exception's message/reason, which would be fragile given the ^5.2.1 caret-pinned js-yaml dependency.

parseFrontmatter() falls back to {} via ?? (not ||) so legitimate falsy scalar documents (0, false, null) aren't miscoerced.

No changes needed in syntax.ts or json-render.ts — both already handle an undefined/falsy result.

📝 Checklist

  • I have linked an issue or discussion.
  • I have run pnpm verify and it passes.
  • I have updated the documentation accordingly.

Empty, whitepsace-only, or comment-only YAML
props/frontmatter blocks throw YAMLException because
of finding an empty document. Fixes comarkdown#319.
@adamdehaven
adamdehaven requested a review from farnabaz as a code owner August 1, 2026 22:50
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

@adamdehaven is attempting to deploy a commit to the NuxtLabs Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread packages/comark/src/internal/yaml.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

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

@comark/angular

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

@comark/ansi

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

@comark/html

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

@comark/nuxt

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

@comark/react

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

@comark/svelte

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

@comark/vue

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

commit: 1657bcf

@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.

Thanks

@farnabaz
farnabaz merged commit 71fbe96 into comarkdown:main Aug 3, 2026
4 of 12 checks passed
@adamdehaven
adamdehaven deleted the fix/issue-319-empty-yaml-props-throw-error branch August 3, 2026 14:08
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