Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

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

Geschlossen
#451 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
react, typescript
Bereich
frontend

Rechercherichtung

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 {}.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
TypeScript
Sterne
402
Forks
32
Ø Merge
12 Std. 1 Min.
Gemergte PRs (30 T.)
80

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus voidzero-dev/void

Alle Issues in voidzero-dev/void

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.