Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

useFrontmatter() returns {} in layouts with the React adapter

Đã đóng
#451 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Start in @void/md/dist/plugin.mjs at emitReactComponent and @void/react/dist/runtime/pages-server.mjs where layouts wrap page elements; the issue identifies the frontmatter provider and layout placement as the likely cause. Reproduce with the linked project and compare useFrontmatter() in pages/layout.tsx with the page title. Done when the layout receives the Markdown page's frontmatter and the reproduction shows its title instead of {}.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Describe the bug

The Markdown guide says layouts can read the current page's frontmatter with useFrontmatter() (Frontmatter Access). With @void/react, calling it from a layout that wraps a .md page returns {}.

Reproduction

https://github.com/Nkzn/void-md-layout-frontmatter-repro

pnpm install
pnpm dev   # or: pnpm build && pnpm preview

pages/layout.tsx renders JSON.stringify(useFrontmatter()) around pages/index.md (title: Hello from frontmatter).

  • Expected: layout frontmatter: {"title":"Hello from frontmatter",...}
  • Actual: layout frontmatter: {} (while <title> is correctly Hello from frontmatter)
Possible cause

The React component generated by @void/md provides the frontmatter context only around the Markdown body:

  • @void/md/dist/plugin.mjs (emitReactComponent, around L69–L115): MarkdownPage returns <FrontmatterContext.Provider value={__frontmatter}>…</FrontmatterContext.Provider>.
  • @void/react/dist/runtime/pages-server.mjs (L121): layouts are wrapped outside the page element, so they render above the provider and useContext(FrontmatterContext) falls back to {}.
Workaround

Pass the page path to the layout (e.g. one named layout per page) and read the frontmatter from @void/md/pages instead of useFrontmatter().

Versions
Ngôn ngữ chính
TypeScript
Star
402
Fork
32
Merge trung bình
12 giờ 28 phút
Pull request đã merge (30 ngày)
77

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của voidzero-dev/void

Tất cả issue của voidzero-dev/void

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.