Repository navigation
Description
Description
The page:metadata plugin hook is documented and the dispatch infrastructure exists in HookPipeline, but the hook never fires when a public page is rendered. This blocks any plugin that needs to inject metadata, JSON-LD, og:tags, or other head contributions on public pages (SEO plugins, analytics, social embeds, schema markup).
Root cause: in dist/astro/middleware.mjs around line 1542, the middleware sets locals.emdash with all the API handlers but does not include collectPageMetadata or collectPageFragments. Since getPageRuntime() in src/page/index.ts requires both methods to be present, it always returns undefined, EmDashHead.astro skips the plugin contributions branch entirely, and only the base contributions (BlogPosting JSON-LD from core) are rendered.
Diagnosis: I patched the dist bundle with debug logs and confirmed:
HookPipeline.registerPluginsIS called with my plugin- The plugin's
hooksobject contains"page:metadata" registerPluginHook(plugin, "page:metadata")succeeds without warnings- But
hasHooks("page:metadata")andrunPageMetadata()are never invoked when a page renders, becausegetPageRuntime()returnsundefined
Suggested fix: add the two methods to locals.emdash in the Astro middleware:
locals.emdash = {
// ... existing handlers ...
collectPageMetadata: runtime.collectPageMetadata.bind(runtime),
collectPageFragments: runtime.collectPageFragments.bind(runtime),
};
This single change should restore the entire page:metadata and page:fragments hook dispatch path.
Impact: any plugin that needs to inject head content on public pages is blocked. From a plugin author's perspective everything looks correct (the hook is documented, the manifest accepts it, registration succeeds without errors), which makes this a particularly silent failure.
I'm building an SEO plugin that depends on this hook. Happy to submit a PR with the fix if it would help.
Steps to reproduce
-
Create a Standard plugin with
page:metadatahook:// index.ts export function myPlugin(): PluginDescriptor { return { id: "my-plugin", version: "0.1.0", format: "standard", entrypoint: "@my-org/my-plugin/sandbox", capabilities: [], }; }// sandbox-entry.ts import { definePlugin } from "emdash"; export default definePlugin({ hooks: { "page:metadata": async (event, ctx) => { ctx.log.info("page:metadata fired"); return [ { kind: "meta", name: "x-test", content: "hello", key: "x-test" }, ]; }, }, }); -
Register in astro.config.mjs:
plugins: [myPlugin()],
- Start the dev server and load any public page (e.g., /posts/my-post).
- Expected: the log fires and appears in the rendered HTML.
- Actual: no log appears, no meta tag in the HTML. Only the core's base SEO contributions (BlogPosting JSON-LD) are rendered.
Environment
- emdash version: 0.1.0
- Node.js version: 22.22.2
- Runtime: Node.js (
@astrojs/nodestandalone,output: "server") - OS: macOS
- Plugin format: Standard (config-based loading via
plugins: []in astro.config.mjs) - Theme: default
npm create emdash@latestblog template (uses<EmDashHead page={pageCtx} />inBase.astro)
Logs / error output
No errors. The hook silently does not fire. Confirmed via dist bundle patch:
[HOOK-DEBUG] registerPlugins called with 4 plugins
[HOOK-DEBUG] plugin: my-plugin hooks: [ 'page:metadata' ]
Plugin is registered, no skip warnings, but `hasHooks("page:metadata")` and `runPageMetadata()` never get called when pages render. Tracing through `dist/astro/middleware.mjs`:
- `EmDashHead.astro` calls `getPageRuntime(Astro.locals)`
- `getPageRuntime` returns `undefined` because `locals.emdash` does not have `collectPageMetadata`
- The `if (runtime)` branch is skipped, so `runtime.collectPageMetadata(page)` is never called
- Only base contributions are rendered, plugin contributions are silently dropped
Activity
davidrc commentedon Apr 8, 2026
Apologies — I missed #118 and #166 when filing this, which describe the same bug with more detail. #119 is an open PR fixing it by removing the anonymous fast-path in the middleware.
A small extra data point from my investigation: I confirmed the broken path end-to-end by patching
node_modules/emdash/dist/search-DG603UrT.mjswith debug logs inHookPipeline.registerPlugins,hasHooks, andrunPageMetadata. The log trace showed:registerPluginsis called and registerspage:metadatafor my plugin (no capability skip warning)Object.keys(plugin.hooks)at registration timehasHooks("page:metadata")andrunPageMetadata()are never invoked when a page rendersThis confirms the diagnosis in #118:
getPageRuntime()returnsundefinedbecauselocals.emdashnever getscollectPageMetadata/collectPageFragmentsbound, soEmDashHead.astrotakes the fallback branch that skips plugin contributions entirely.Also worth noting: in my reproduction this happens for both anonymous and authenticated visitors (I was testing via
/_emdash/api/auth/dev-bypasswith a valid session cookie). If the fix in #119 only addresses the anonymous fast-path, please double-check that the authenticated path also populatescollectPageMetadatainlocals.emdash.Closing as duplicate of #118. +1 to merging #119.