Skip to content

feat(core): apply SEO panel values by default in EmDashHead - #1963

Merged
ascorbic merged 5 commits into
emdash-cms:mainfrom
swissky:feat/1518-emdashhead-panel-seo
Sep 10, 2026
Merged

ascorbic merged 5 commits into
emdash-cms:mainfrom
swissky:feat/1518-emdashhead-panel-seo

Conversation

@swissky

@swissky swissky commented Jul 11, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Makes <EmDashHead> apply the entry's SEO panel values (title, description, image, canonical, noindex) automatically on content pages — with zero additional database queries, addressing the review feedback.

Discussion: #1956

How it stays at zero queries. The loader's single-entry path already folds the _emdash_seo row into the entry query as a JSON subselect. This PR primes a request-scoped cache from that folded data at the moments it materializes:

  • the loader's single-entry path (live and revision branches), and
  • the object-cache revive path in getEmDashEntry, so warm cache hits (where the loader never runs) behave identically to cold ones.

<EmDashHead> — and the body fragment components, so page:fragments hooks see the same context everywhere — then peek that cache and overlay the panel values onto the page context before the base contributions, JSON-LD builders, and plugin hooks consume it. The peek is a plain map read and never falls back to a database lookup. The query-count snapshots (scripts/query-counts.snapshot.*.json) are unchanged in this PR: Δ 0 on every route, including the content-page routes.

Precedence is unchanged: plugin contributions still override everything via first-wins dedup; the panel values replace only the template-provided base fields. The <title> element remains the template's responsibility (head components can't replace it), so seo.title feeds og:title/twitter:title/JSON-LD headline only.

Scope: the overlay applies when the entry was fetched through getEmDashEntry() or a live content collection in the same request. Prerendered pages and hand-rolled queries keep using getSeoMeta() — documented in the site-settings guide.

Closes #1518

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: getSeoMeta defaults: implement suggestion 2 from #1518 #1956
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Cursor + Claude Fable 5

Screenshots / test output

Not applicable (no admin UI change; rendered head output is covered by the unit suites below).

Test coverage added:

  • tests/unit/page/seo-contributions.test.ts — overlay precedence (description/og/twitter/canonical/robots/JSON-LD consistency) and the request-scoped cache (isolation across requests and entries, no-context safety).
  • tests/unit/loader-seo.test.ts — the loader primes the cache keyed by the content-row id; entries without an SEO row prime nothing.
  • tests/unit/object-cache-content.test.ts — warm object-cache hits prime the cache from the snapshot (the loader never runs on that path).

@changeset-bot

changeset-bot Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8262e0a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
create-emdash Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/release-service Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@1963

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@1963

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@1963

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@1963

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@1963

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@1963

emdash

npm i https://pkg.pr.new/emdash@1963

create-emdash

npm i https://pkg.pr.new/create-emdash@1963

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@1963

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@1963

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@1963

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@1963

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@1963

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@1963

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@1963

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@1963

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@1963

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@1963

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@1963

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@1963

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@1963

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@1963

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@1963

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@1963

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@1963

commit: 8262e0a

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right change: it implements the maintainer-suggested default behavior from #1518 by folding SEO panel values into <EmDashHead> without requiring templates to wire getSeoMeta(). The precedence story (plugins → site → panel → template base) is clearly documented, the implementation is mostly idiomatic, and the query-cost gating via getCollectionInfo() is a sensible optimization.

I read the full diff, the changed source files, the existing SeoRepository/resolvePageMetadata/requestCached machinery, and the schema route/handlers. The PR adds good unit tests, updates query-count snapshots correctly, documents the change, and includes a clean changeset. I did not find SQL-safety, authorization, or XSS issues in the new code.

Two issues remain:

  1. Schema cache invalidation gap. getCollectionInfo() caches under CacheNamespace.SCHEMA, but collection create/update/delete routes never call invalidateSchemaObjectCache(). On sites that have an object-cache backend configured, enabling SEO on a collection can leave the cached hasSeo: false in place for up to the TTL, so <EmDashHead> will silently skip the panel lookup despite SEO being enabled. This is both an AGENTS.md invalidation gap and a correctness problem for the new gating logic. The fix is straightforward: invalidate CacheNamespace.SCHEMA from the collection write paths (route or handler).

  2. JSON-LD panel values. The panel image and canonical are emitted as meta/link/property tags but are not fed into buildBlogPostingJsonLd(), which still reads page.canonical and page.seo?.ogImage || page.image. That means <link rel="canonical"> and og:url can say one thing while the structured-data url/mainEntityOfPage say another. Templates that still call getSeoMeta() populate page.seo, so they won't have this inconsistency. Worth a follow-up to either fold panel values into the page context or generate JSON-LD from resolved metadata.

Beyond those, the implementation is clean and I'd be happy to see it land once the invalidation is wired.

if (page.content) {
const { collection, id } = page.content;
const info = await getCollectionInfo(collection);
if (info?.hasSeo) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This gates the _emdash_seo lookup on info?.hasSeo from getCollectionInfo(). That function caches under CacheNamespace.SCHEMA via cachedQuery, but collection create/update/delete routes only call emdash.invalidateUrlPatternCache() and never invalidateSchemaObjectCache(). On deployments with an object-cache backend, an admin enabling SEO on a collection can leave a stale hasSeo: false in the cache for the TTL, so <EmDashHead> will silently skip the panel lookup and editor-set SEO values won't render.

Add invalidateSchemaObjectCache() to the collection write paths (alongside the existing URL-pattern cache invalidation) so the schema cache is flushed when has_seo or other collection metadata changes.

Suggested change
if (info?.hasSeo) {
if (info?.hasSeo) {

Then, in the collection create/update/delete routes/handlers:

import { invalidateSchemaObjectCache } from "emdash";
// ...after the write succeeds:
invalidateSchemaObjectCache();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invalidation already exists: since #1378, invalidateUrlPatternCache() also calls invalidateSchemaObjectCache() ("every schema-mutation path already routes through here" — see its JSDoc in query.ts), and the collection create/update/delete routes all call emdash.invalidateUrlPatternCache() after the write. So enabling SEO on a collection busts the SCHEMA namespace the hasSeo gate reads from. I've extended the comment at the gate (70ead45) to make that dependency explicit.

* Returns an empty array when no panel field is set, so pages without
* SEO data are unaffected.
*/
export function generateSeoPanelContributions(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] Panel values are emitted as meta/link/property contributions, but they don't reach buildBlogPostingJsonLd() in the base layer. That builder still reads page.canonical and page.seo?.ogImage || page.image, so a panel canonical or image can disagree with the emitted <link rel="canonical">, og:url, and og:image. Templates that still call getSeoMeta() avoid this because they populate page.seo, which feeds JSON-LD.

Consider a follow-up that either folds panel SEO into the page context or generates the JSON-LD graph from the resolved metadata layer so structured data stays consistent with the head tags.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in 70ead45 by switching from a separate contribution layer to overlaying the panel onto the page context (applySeoPanelToPageContext) before anything consumes it. Base contributions, buildBlogPostingJsonLd(), and plugin page:metadata hooks now all see the same panel-resolved values, so structured data can't disagree with the head tags. The twitter:card large-image upgrade also falls out of the base layer's own logic now. Plugins still override the rendered output via first-wins dedup. Added a regression test asserting the JSON-LD headline/image match the panel values.

@github-actions

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond review/needs-rereview New commits since the last review and removed review/needs-review No maintainer or bot review yet review/awaiting-author Reviewed; waiting on the author to respond labels Jul 12, 2026
@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Jul 12, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a re-review of #1963. The two issues from the previous review are now resolved:

  1. Schema cache invalidation is wired correctly. The collection create/update/delete routes (packages/core/src/astro/routes/api/schema/collections/index.ts and [slug]/index.ts) call emdash.invalidateUrlPatternCache(), which in turn bumps CacheNamespace.SCHEMA. That invalidates the getCollectionInfo() cache used to gate the _emdash_seo lookup, so toggling hasSeo on a collection no longer leaves stale hasSeo: false entries behind.

  2. JSON-LD now stays consistent with the head tags. applySeoPanelToPageContext() overlays page.canonical and page.seo.ogImage with the panel's absolutized canonical and image before generateBaseSeoContributions() calls buildBlogPostingJsonLd(), so the structured-data url/mainEntityOfPage and image match <link rel="canonical"> / og:url / og:image.

Overall this is the right change for #1518: it applies SEO panel values by default in <EmDashHead> without requiring every template to wire getSeoMeta(), the precedence story (plugins → site → panel → template base) is clearly documented, query-count snapshots are updated honestly, and the changeset is clean.

I have two minor polish suggestions that don't block merge:

  • The panel image should also be reflected on page.image so plugin page:metadata hooks reading the top-level field see the same value as the base/JSON-LD consumers.
  • The JSON-LD consistency test should assert url (and/or mainEntityOfPage) in addition to headline and image, since the canonical overlay is the main fix being verified.

Comment on lines +183 to +192
return {
...page,
description: seo.description || page.description,
canonical: canonical || page.canonical,
seo: {
...page.seo,
ogTitle: seo.title || page.seo?.ogTitle,
ogDescription: seo.description || page.seo?.ogDescription,
ogImage: image || page.seo?.ogImage,
robots: seo.noIndex ? "noindex, nofollow" : page.seo?.robots,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] The overlay updates description, canonical, and seo.ogImage, but it leaves page.image holding the template's original value. Because the overlaid resolvedPage is what plugin page:metadata hooks receive, a hook that reads page.image directly (instead of page.seo?.ogImage) will disagree with the base/JSON-LD output.

For consistency with the documented behavior — "editor-set panel values override whatever the template passed in" — mirror the image into the top-level field as well:

Suggested change
return {
...page,
description: seo.description || page.description,
canonical: canonical || page.canonical,
seo: {
...page.seo,
ogTitle: seo.title || page.seo?.ogTitle,
ogDescription: seo.description || page.seo?.ogDescription,
ogImage: image || page.seo?.ogImage,
robots: seo.noIndex ? "noindex, nofollow" : page.seo?.robots,
return {
...page,
description: seo.description || page.description,
canonical: canonical || page.canonical,
image: image || page.image,
seo: {
...page.seo,
ogTitle: seo.title || page.seo?.ogTitle,
ogDescription: seo.description || page.seo?.ogDescription,
ogImage: image || page.seo?.ogImage,
robots: seo.noIndex ? "noindex, nofollow" : page.seo?.robots,
},
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — the overlay now also mirrors the resolved panel image into the top-level page.image, so page:metadata hooks reading page.image agree with og:image and the JSON-LD graph.

Comment on lines +256 to +259
expect(graph).toMatchObject({
headline: "Panel Title",
image: "https://example.com/_emdash/api/media/file/01KSMEDIA",
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] The test name promises that JSON-LD stays consistent with the head tags for both image and canonical, but the assertion only checks headline and image. Since the canonical overlay is the other half of the consistency fix, also assert url (and/or mainEntityOfPage) so a regression in buildBlogPostingJsonLd reading page.canonical would be caught:

Suggested change
expect(graph).toMatchObject({
headline: "Panel Title",
image: "https://example.com/_emdash/api/media/file/01KSMEDIA",
});
expect(graph).toMatchObject({
headline: "Panel Title",
image: "https://example.com/_emdash/api/media/file/01KSMEDIA",
url: "https://example.com/posts/other-post",
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — the test now also asserts url and mainEntityOfPage["@id"] (both fed from page.canonical), so a canonical regression in buildBlogPostingJsonLd is caught.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Jul 13, 2026
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Jul 19, 2026
@swissky swissky added bot:review Trigger an emdashbot code review on this PR and removed bot:review Trigger an emdashbot code review on this PR labels Jul 19, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of #1963. The implementation is the right change for #1518: applying SEO panel values by default in <EmDashHead> fits the architecture, the precedence story is documented, and the query-cost impact is gated honestly behind getCollectionInfo().

Both issues from the previous review are now addressed:

  1. Schema cache invalidation — collection create/update/delete routes call emdash.invalidateUrlPatternCache(), which bumps CacheNamespace.SCHEMA and invalidates the getCollectionInfo() cache used to gate the _emdash_seo lookup.
  2. JSON-LD consistency — applySeoPanelToPageContext() overlays page.canonical and page.seo.ogImage (and now page.image) with the panel's resolved values before generateBaseSeoContributions() calls buildBlogPostingJsonLd(), so structured data matches the head tags. The unit test now asserts url and mainEntityOfPage as well as headline and image.

I checked the changed code against AGENTS.md conventions: the new _emdash_seo lookup is a parameterized Kysely query (no SQL injection risk), no admin UI strings are added, the changeset is present and user-focused, and the query-count snapshots reflect the new requests accurately. The PK lookup on _emdash_seo is well-indexed, and the per-row query is request-cached.

No remaining blocking issues or suggestions. LGTM.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Jul 19, 2026
@github-actions github-actions Bot added the review/approved Approved; no new commits since label Jul 19, 2026
@github-actions github-actions Bot added size/XL and removed review/awaiting-author Reviewed; waiting on the author to respond labels Sep 10, 2026
@swissky

swissky commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

@ascorbic Reworked to zero extra queries — the earlier version's per-pageload _emdash_seo lookup is gone.

Since the loader now folds the SEO row into the single-entry query as a JSON subselect (the #1270 hydration work), the panel data is already in hand whenever an entry is fetched. The rework primes a request-scoped cache from that folded data (in the loader, and on the object-cache revive path so warm hits behave the same), and <EmDashHead> just peeks the cache and overlays the values — a map read that never falls back to a database lookup. Pages whose entry wasn't fetched through a loader in the request (prerendered pages, hand-rolled queries) simply get no overlay and keep using getSeoMeta(); that scope is documented.

The query-count snapshots are untouched in this PR: Δ 0 on every route, verified by pnpm query-counts against the existing main snapshots.

@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a re-review of #1963. The implementation is still the right change for #1518: priming a request-scoped cache from the loader's folded _emdash_seo column and overlaying the panel values onto PublicPageContext before <EmDashHead>, the body fragment components, and plugin hooks consume it is the idiomatic, zero-query way to make SEO panel values apply by default. I re-read the changed source, tests, and docs and verified the query-count snapshot files are not touched.

The two issues that blocked the previous review—schema cache invalidation and JSON-LD consistency—remain addressed in the current head: the object-cache revive path in query.ts primes the panel cache from the snapshot when the loader never runs, and applySeoPanelToPageContext() feeds the same resolved values into base contributions and buildBlogPostingJsonLd() so structured data matches the head tags.

However, the current diff introduces two new needs_fixing items that should be addressed before merge:

  1. AGENTS.md comment discipline. New comments, module docstrings, and test names repeatedly reference #1518. AGENTS.md forbids issue/PR references in code because comments are evergreen; the context belongs in the commit message and PR description, not in comments or test identifiers.
  2. Documentation inaccuracy. docs/src/content/docs/guides/site-settings.mdx says the overlay applies to pages that fetch through getEmDashEntry() or getEntry() on a live content collection. EmDash exposes getEmDashEntry() / getEmDashCollection(); Astro's live APIs are getLiveEntry() / getLiveCollection(). getEntry() is the static Astro API, so this wording is ambiguous and likely to confuse readers.

Non-blocking suggestion: packages/core/src/seo/index.ts still reimplements canonical resolution and misses the new protocol-relative handling added in resolveSeoCanonicalUrl(). Consider making getSeoMeta() use resolveSeoCanonicalUrl() so manual and automatic paths behave identically for edge-case canonical values.

* a content entry (`page.content` is set) that was fetched through EmDash's
* content APIs in this request (`getEmDashEntry()` or the live loader,
* including warm object-cache hits), the entry's SEO panel values are overlaid
* onto the page context automatically (#1518): the entry query folds the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The module docstring references issue #1518. AGENTS.md forbids issue/PR references in comments because they are evergreen and quickly become stale narrative. Remove the issue reference.

Suggested change
* onto the page context automatically (#1518): the entry query folds the
* onto the page context automatically: the entry query folds the

const siteSettings = await getSiteSettings();
const siteUrl = page.siteUrl || siteSettings.url || new URL(page.url).origin;

// SEO panel values for the rendered content entry (#1518), primed by

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This inline comment includes an issue reference (#1518). AGENTS.md comment discipline prohibits issue/PR references in code. Remove it.

Suggested change
// SEO panel values for the rendered content entry (#1518), primed by
// SEO panel values for the rendered content entry, primed by

Comment thread packages/core/src/loader.ts Outdated
if (entrySeo) {
entryData.seo = entrySeo;
// Prime the request cache so <EmDashHead> can apply the panel
// values without its own _emdash_seo query (#1518). Keyed by the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This explanatory comment adds an issue number (#1518). The rationale it expresses is useful; the issue reference violates AGENTS.md. Remove the parenthetical.

Suggested change
// values without its own _emdash_seo query (#1518). Keyed by the
// values without its own _emdash_seo query. Keyed by the


/**
* Resolve the page context for rendering: overlay the entry's SEO panel
* values when they were primed for this request (#1518).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The docstring for resolveSeoPanelPage references #1518. AGENTS.md forbids issue references in source comments. Remove the parenthetical.

Suggested change
* values when they were primed for this request (#1518).
* values when they were primed for this request.
*
* Used by `<EmDashHead>`, `<EmDashBodyStart>`, and `<EmDashBodyEnd>` so

}

/**
* Overlay a content entry's SEO panel data onto the page context (#1518).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The docstring for applySeoPanelToPageContext references #1518. AGENTS.md forbids issue references in source comments. Remove the parenthetical.

Suggested change
* Overlay a content entry's SEO panel data onto the page context (#1518).
* Overlay a content entry's SEO panel data onto the page context.
*
* `<EmDashHead>` applies this overlay before anything consumes the context:

Comment thread packages/core/src/page/seo-panel.ts Outdated
@@ -0,0 +1,47 @@
/**
* Request-scoped hand-off of SEO panel data from the entry query to the
* render components (#1518).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This module-level docstring references #1518. AGENTS.md prohibits issue/PR numbers in comments. Remove the reference.

Suggested change
* render components (#1518).
* render components.
*
* The loader's single-entry path already folds the `_emdash_seo` row into

Comment on lines +100 to +109
* applySeoPanelToPageContext() — #1518.
*
* Bug context: values set in the admin SEO panel were silently ignored
* unless the template manually wired getSeoMeta(). EmDashHead now fetches
* the panel row for content pages and overlays it onto the page context
* before base contributions and JSON-LD are generated, so editor-set
* values apply by default and structured data stays consistent with the
* head tags.
*/
describe("applySeoPanelToPageContext (#1518)", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The block-level test comment and the describe name both reference #1518. AGENTS.md forbids issue references in comments and test identifiers. Replace them with descriptive prose.

Suggested change
* applySeoPanelToPageContext() — #1518.
*
* Bug context: values set in the admin SEO panel were silently ignored
* unless the template manually wired getSeoMeta(). EmDashHead now fetches
* the panel row for content pages and overlays it onto the page context
* before base contributions and JSON-LD are generated, so editor-set
* values apply by default and structured data stays consistent with the
* head tags.
*/
describe("applySeoPanelToPageContext (#1518)", () => {
/**
* applySeoPanelToPageContext() overlays values from the admin SEO panel
* onto the page context. Previously they were silently ignored unless the
* template wired getSeoMeta() by hand; EmDashHead now applies them by default
* and keeps structured data consistent with the head tags.
*/
describe("applySeoPanelToPageContext overlays SEO panel values", () => {

expect((data.seo as Record<string, unknown>).noIndex).toBe(true);
});

it("primes the request-scoped SEO panel cache keyed by the content-row id (#1518)", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This test name includes #1518. AGENTS.md prohibits issue references in code, including test identifiers. Remove the reference.

Suggested change
it("primes the request-scoped SEO panel cache keyed by the content-row id (#1518)", async () => {
it("primes the request-scoped SEO panel cache keyed by the content-row id", async () => {

expect(result.entries[0]!.data).not.toHaveProperty("draftRevisionId");
});

it("primes the SEO panel cache when an entry is served from the object cache (#1518)", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] This test name includes #1518. AGENTS.md prohibits issue references in code, including test identifiers. Remove the reference.

Suggested change
it("primes the SEO panel cache when an entry is served from the object cache (#1518)", async () => {
it("primes the SEO panel cache when an entry is served from the object cache", async () => {


<Aside>
On server-rendered content pages that include the `<EmDashHead>` component and fetch their entry
through `getEmDashEntry()` or `getEntry()` on a live content collection, values from the entry's

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[needs fixing] The aside tells readers the overlay applies when fetching through getEmDashEntry() or getEntry() on a live content collection. EmDash exposes getEmDashEntry() and getEmDashCollection(); Astro live collections use getLiveEntry()/getLiveCollection(). Mentioning getEntry()—Astro's static content API—is ambiguous and likely to mislead. Use the EmDash helper name.

Suggested change
through `getEmDashEntry()` or `getEntry()` on a live content collection, values from the entry's
through `getEmDashEntry()` or `getEmDashCollection()` on a live content collection, values from the entry's

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026
@swissky

swissky commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Both findings addressed in 55b9e47: dropped the issue references from the new comments, docstrings, and test names, and the site-settings guide now names getEmDashEntry() / Astro's getLiveEntry() precisely. Left getSeoMeta()'s canonical resolution as-is for this PR — switching it to resolveSeoCanonicalUrl() would change the rendered canonical on existing sites using the manual path (root-relative values would become absolute), which deserves its own changeset; happy to follow up separately.

@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right change for #1518. Folding _emdash_seo into the existing entry query, priming a request-scoped cache, and overlaying the panel values onto PublicPageContext before plugins, base contributions, and JSON-LD consume it is the idiomatic, zero-query way to make <EmDashHead> apply SEO panel values by default. I re-read the updated source, the new tests (loader priming, object-cache revive, and overlay behavior), the docs, and confirmed the query-count snapshot files are still untouched.

The two issues that blocked the previous review are addressed in this head: all new module and component comments are free of issue/PR references, and the JSON-LD structured-data path (buildBlogPostingJsonLd) now consumes the same resolvedPage, so structured data stays consistent with the rendered head tags.

Only polish remains — one docs sentence is still ambiguous, the changeset is one dense paragraph, and the documented manual fallback getSeoMeta() now diverges from the new automatic canonical resolver for edge-case panel values.


Findings

  • [suggestion] docs/src/content/docs/guides/site-settings.mdx:175-176

    The aside correctly names getEmDashEntry(), but “Astro's getLiveEntry() on the EmDash collection” is still ambiguous: the EmDash Astro collection is the internal _emdash collection, and readers won't know the required arguments. Either mention the internal collection name explicitly or limit the guidance to the public helper.

    	through `getEmDashEntry()` or Astro's `getLiveEntry('_emdash', …)` on the
    	EmDash collection, values from the entry's
    
  • [suggestion] .changeset/emdashhead-seo-panel.md:3

    The changeset is accurate, but it is one dense paragraph that buries the affected surface, the note for plugin authors, and the limitations. .changeset/README.md expects h4-or-lower headings in longer entries. Break it into sections so a reader scanning the CHANGELOG can quickly tell whether the release affects them.

    ---
    "emdash": minor
    ---
    
    `<EmDashHead>` now applies the entry's SEO panel values (title, description, image, canonical, noindex) automatically on server-rendered content pages.
    
    #### Affected pages
    
    Pages that include `<EmDashHead>` and fetch their entry through `getEmDashEntry()` — or the EmDash live collection directly — receive the overlay. This includes warm object-cache hits, because `getEmDashEntry()` primes the same request-scoped cache from the cached snapshot when the loader never runs.
    
    #### What editors can override
    
    Editor-set panel values replace the template-provided base fields for `description`, `og:title`, `og:description`, `og:image`, canonical URL, and robots. They also feed the JSON-LD structured data, so head tags and structured data stay in sync.
    
    #### What plugins see
    
    Plugin `page:metadata` and `page:fragments` hooks receive the overlaid `page` context, but plugin contributions still win via first-wins dedup.
    
    #### What does not change
    
    - The `<title>` element remains the template's responsibility.
    - Prerendered pages and pages that bypass `<EmDashHead>` keep using `getSeoMeta()`.
    - No additional database query is made; the panel data rides along on the entry query the page already runs.
    
  • [suggestion] packages/core/src/seo/index.ts:143-145

    getSeoMeta() still resolves canonical by hand and mishandles protocol-relative panel values — with siteUrl set, a canonical like //other.example/page becomes https://example.com//other.example/page. The new automatic overlay path already handles this correctly via resolveSeoCanonicalUrl(). Since getSeoMeta() is the documented fallback for prerendered and hand-rolled pages, it should reuse the same resolver so the same SEO panel value produces the same canonical everywhere.

    import { buildSeoImageUrl, resolveSeoCanonicalUrl } from "./media-url.js";
    
    	// Canonical: explicit > path-based > null
    	const canonical = seo.canonical
    		? resolveSeoCanonicalUrl(seo.canonical, siteUrl)
    		: siteUrl && path
    			? `${siteUrl.replace(TRAILING_SLASH_RE, "")}${path.startsWith("/") ? path : `/${path}`}`
    			: null;
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026
@swissky

swissky commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Applied both doc suggestions in 8f7e8db: the aside now names only the public helper (getEmDashEntry()), and the changeset is restructured into your suggested sections.

On the third suggestion (getSeoMeta() reusing resolveSeoCanonicalUrl()): the protocol-relative mangling described doesn't actually occur — //other.example/page starts with /, so it takes the passthrough branch in seo/index.ts (the absolutizing branch requires !seo.canonical.startsWith("/")), and is returned unchanged. The real divergence between the two paths is root-relative values: getSeoMeta() passes /foo through while the overlay absolutizes it. Unifying them means changing getSeoMeta()'s output on existing sites, which I'd rather do as a focused follow-up with its own changeset than fold into this PR.

@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a re-review of #1963. The blockers from the previous pass are resolved: the new module comments no longer reference issue/PR numbers, the JSON-LD builders now consume the same resolvedPage as the head tags, the changeset has been restructured with h4 headings, and the site-settings docs have dropped the ambiguous getLiveEntry() wording in favor of the public getEmDashEntry() helper.

The overall approach remains sound: folding _emdash_seo into the existing entry query, priming a request-scoped cache, and overlaying the panel values onto PublicPageContext before plugins, base contributions, and JSON-LD consume it is the idiomatic zero-query way to make <EmDashHead> apply SEO panel values by default.

Two issues are still open and one minor inconsistency is new:

  1. getSeoMeta() canonical handling diverges from the new automatic path (packages/core/src/seo/index.ts). The PR's new resolveSeoCanonicalUrl() correctly absolutizes root-relative panel canonicals (e.g. /custom-path becomes https://example.com/custom-path), but the documented manual fallback still returns them root-relative. The same SEO panel value now produces different canonical URLs depending on whether the page uses <EmDashHead> or getSeoMeta(). Reusing resolveSeoCanonicalUrl() in getSeoMeta() fixes it.

  2. Changeset overclaims collection support (.changeset/emdashhead-seo-panel.md). The overlay is only primed in the loader's single-entry (loadEntry) path and in the getEmDashEntry() object-cache revive path. Entries rendered from multi-entry getEmDashCollection() / getLiveCollection() results are not covered, because the collection query does not fold _emdash_seo. The changeset currently says live-collection-direct pages receive the overlay, which is not implemented.

  3. buildSeoImageUrl() doesn't handle protocol-relative URLs (packages/core/src/seo/media-url.ts). The new sibling resolveSeoCanonicalUrl() treats //host/path as already-qualified, but buildSeoImageUrl() treats it as a bare media id and produces a broken doubled-path URL. Returning protocol-relative references unchanged (or rejecting them, as absolutizeMediaUrl() does) would keep the two resolvers consistent.

All three are fixable with small, safe edits.


Findings

  • [needs fixing] packages/core/src/seo/index.ts:154

    The manual fallback canonical resolver still returns root-relative panel values unchanged when siteUrl is set, while the new automatic overlay path (resolveSeoCanonicalUrl()) correctly absolutizes them. The same panel value now yields https://example.com/custom-path via <EmDashHead> but /custom-path via getSeoMeta(), which is a real SEO consistency regression introduced by the divergence.

    import { buildSeoImageUrl, resolveSeoCanonicalUrl } from "./media-url.js";
    
    	// Canonical: explicit > path-based > null
    	let canonical: string | null = null;
    	if (seo.canonical) {
    		canonical = resolveSeoCanonicalUrl(seo.canonical, siteUrl);
    	} else if (siteUrl && path) {
    		const safePath = path.startsWith("/") ? path : `/${path}`;
    		canonical = `${siteUrl.replace(TRAILING_SLASH_RE, "")}${safePath}`;
    	}
    
  • [needs fixing] .changeset/emdashhead-seo-panel.md:9

    The overlay is only primed on the loader's single-entry (loadEntry) path and in the getEmDashEntry() object-cache revive path. Multi-entry collection results from getEmDashCollection() / getLiveCollection() do not fold _emdash_seo and therefore do not receive the overlay, so the claim that the EmDash live collection directly receives it is incorrect.

    Pages that include `<EmDashHead>` and fetch their entry through `getEmDashEntry()` receive the overlay. This includes warm object-cache hits, because `getEmDashEntry()` primes the same request-scoped cache from the cached snapshot when the loader never runs. Multi-entry collection results (e.g. `getEmDashCollection()`) are not currently covered.
    
  • [suggestion] packages/core/src/seo/media-url.ts:17

    buildSeoImageUrl() treats protocol-relative references (//cdn.example.com/x.png) as bare media ids and produces a broken doubled-path URL. The new resolveSeoCanonicalUrl() next to it correctly recognizes //host/path as already qualified; the image resolver should do the same, or reject protocol-relative input like absolutizeMediaUrl() does.

    export function buildSeoImageUrl(imageRef: string, siteUrl?: string): string {
    	// Already absolute — use as-is.
    	if (ABSOLUTE_URL_RE.test(imageRef)) {
    		return imageRef;
    	}
    
    	// Protocol-relative references are qualified, not bare media ids.
    	if (imageRef.startsWith("//")) {
    		return imageRef;
    	}
    
    	// Root-relative path (already includes the media API prefix). Without
    	// this branch we'd re-prefix and produce a doubled path that 404s.
    	if (imageRef.startsWith("/")) {
    		return siteUrl ? `${siteUrl.replace(TRAILING_SLASH_RE, "")}${imageRef}` : imageRef;
    	}
    
    	// Bare media id — build the full media API path.
    	const mediaPath = `/_emdash/api/media/file/${imageRef}`;
    	return siteUrl ? `${siteUrl.replace(TRAILING_SLASH_RE, "")}${mediaPath}` : mediaPath;
    }
    

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026
@swissky

swissky commented Sep 10, 2026

Copy link
Copy Markdown
Member Author

Addressed the latest review in e98bada:

  • Canonical divergence: getSeoMeta() now resolves an explicit panel canonical through the same resolveSeoCanonicalUrl() as the <EmDashHead> overlay — root-relative values are absolutized against the site URL, protocol-relative values pass through. Two integration tests cover both shapes.
  • buildSeoImageUrl(): protocol-relative image refs (//cdn.example.com/x.png) now pass through instead of being prefixed into a broken doubled URL. This corrects og:image in the overlay, getSeoMeta(), and sitemap image URLs; the changeset documents it.
  • Changeset scope: "Affected pages" now states the overlay covers getEmDashEntry() (including warm object-cache hits) and that multi-entry collection results are not covered; the canonical/image resolution changes have their own section.
  • Also updated querying-content.mdx, whose "only reaches the rendered page if your template emits it" wording contradicted the automatic overlay, and guarded the new URL(page.url) origin fallback with URL.canParse so an unparsable page.url degrades to no site URL instead of throwing during render.

Full suite green (6456 tests), lint clean, query-count snapshots unchanged.

@swissky swissky added the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026
@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 10, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall approach remains sound: folding the _emdash_seo row into the existing entry query, priming a request-scoped cache keyed by the content-row id, and overlaying panel values onto PublicPageContext before plugins, base contributions, and JSON-LD consume it is the idiomatic zero-query way to make <EmDashHead> apply SEO panel values by default.

The three blockers from the previous review are all resolved in this revision:

  1. getSeoMeta() canonical handling now delegates to resolveSeoCanonicalUrl(), so a root-relative panel canonical (/custom-path) resolves to the same absolute URL as the <EmDashHead> overlay path.
  2. The changeset no longer overclaims collection coverage and explicitly notes that multi-entry collection results (getEmDashCollection()) are not covered.
  3. buildSeoImageUrl() now treats protocol-relative image references (//cdn.example.com/x.png) as already-qualified, consistent with resolveSeoCanonicalUrl().

I re-read the cache-key paths (loader primes by content-row id; getEmDashEntry() object-cache revive path reads revived.data.id, which is also the content-row id; templates in the demos pass page.data.id as content.id), the overlay precedence, the request-cache semantics, the new unit/integration tests, and the affected docs. No new logic bugs, regressions, or AGENTS.md convention violations were introduced.

@swissky
swissky requested a review from ascorbic September 10, 2026 12:19
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Sep 10, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the extra work on this! Aside from the failing test, this is ready to go.

@ascorbic
ascorbic merged commit b73a133 into emdash-cms:main Sep 10, 2026
52 checks passed
@emdashbot emdashbot Bot mentioned this pull request Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SEO panel fields silently ignored unless the page wires getSeoMeta (footgun for content editors)

2 participants