Repository navigation
feat(core): apply SEO panel values by default in EmDashHead - #1963
Conversation
🦋 Changeset detectedLatest commit: 8262e0a The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
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 |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
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:
-
Schema cache invalidation gap.
getCollectionInfo()caches underCacheNamespace.SCHEMA, but collection create/update/delete routes never callinvalidateSchemaObjectCache(). On sites that have an object-cache backend configured, enabling SEO on a collection can leave the cachedhasSeo: falsein 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: invalidateCacheNamespace.SCHEMAfrom the collection write paths (route or handler). -
JSON-LD panel values. The panel image and canonical are emitted as meta/link/property tags but are not fed into
buildBlogPostingJsonLd(), which still readspage.canonicalandpage.seo?.ogImage || page.image. That means<link rel="canonical">andog:urlcan say one thing while the structured-dataurl/mainEntityOfPagesay another. Templates that still callgetSeoMeta()populatepage.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) { |
There was a problem hiding this comment.
[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.
| if (info?.hasSeo) { | |
| if (info?.hasSeo) { |
Then, in the collection create/update/delete routes/handlers:
import { invalidateSchemaObjectCache } from "emdash";
// ...after the write succeeds:
invalidateSchemaObjectCache();There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
There was a problem hiding this comment.
This is a re-review of #1963. The two issues from the previous review are now resolved:
-
Schema cache invalidation is wired correctly. The collection create/update/delete routes (
packages/core/src/astro/routes/api/schema/collections/index.tsand[slug]/index.ts) callemdash.invalidateUrlPatternCache(), which in turn bumpsCacheNamespace.SCHEMA. That invalidates thegetCollectionInfo()cache used to gate the_emdash_seolookup, so togglinghasSeoon a collection no longer leaves stalehasSeo: falseentries behind. -
JSON-LD now stays consistent with the head tags.
applySeoPanelToPageContext()overlayspage.canonicalandpage.seo.ogImagewith the panel's absolutized canonical and image beforegenerateBaseSeoContributions()callsbuildBlogPostingJsonLd(), so the structured-dataurl/mainEntityOfPageandimagematch<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.imageso pluginpage:metadatahooks reading the top-level field see the same value as the base/JSON-LD consumers. - The JSON-LD consistency test should assert
url(and/ormainEntityOfPage) in addition toheadlineandimage, since the canonical overlay is the main fix being verified.
| 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, |
There was a problem hiding this comment.
[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:
| 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, | |
| }, | |
| }; |
There was a problem hiding this comment.
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.
| expect(graph).toMatchObject({ | ||
| headline: "Panel Title", | ||
| image: "https://example.com/_emdash/api/media/file/01KSMEDIA", | ||
| }); |
There was a problem hiding this comment.
[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:
| 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", | |
| }); |
There was a problem hiding this comment.
Done — the test now also asserts url and mainEntityOfPage["@id"] (both fed from page.canonical), so a canonical regression in buildBlogPostingJsonLd is caught.
There was a problem hiding this comment.
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:
- Schema cache invalidation — collection create/update/delete routes call
emdash.invalidateUrlPatternCache(), which bumpsCacheNamespace.SCHEMAand invalidates thegetCollectionInfo()cache used to gate the_emdash_seolookup. - JSON-LD consistency —
applySeoPanelToPageContext()overlayspage.canonicalandpage.seo.ogImage(and nowpage.image) with the panel's resolved values beforegenerateBaseSeoContributions()callsbuildBlogPostingJsonLd(), so structured data matches the head tags. The unit test now assertsurlandmainEntityOfPageas well asheadlineandimage.
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.
|
@ascorbic Reworked to zero extra queries — the earlier version's per-pageload 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 The query-count snapshots are untouched in this PR: Δ 0 on every route, verified by |
There was a problem hiding this comment.
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:
- 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. - Documentation inaccuracy.
docs/src/content/docs/guides/site-settings.mdxsays the overlay applies to pages that fetch throughgetEmDashEntry()orgetEntry()on a live content collection. EmDash exposesgetEmDashEntry()/getEmDashCollection(); Astro's live APIs aregetLiveEntry()/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 |
There was a problem hiding this comment.
[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.
| * 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 |
There was a problem hiding this comment.
[needs fixing] This inline comment includes an issue reference (#1518). AGENTS.md comment discipline prohibits issue/PR references in code. Remove it.
| // SEO panel values for the rendered content entry (#1518), primed by | |
| // SEO panel values for the rendered content entry, primed by |
| 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 |
There was a problem hiding this comment.
[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.
| // 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). |
There was a problem hiding this comment.
[needs fixing] The docstring for resolveSeoPanelPage references #1518. AGENTS.md forbids issue references in source comments. Remove the parenthetical.
| * 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). |
There was a problem hiding this comment.
[needs fixing] The docstring for applySeoPanelToPageContext references #1518. AGENTS.md forbids issue references in source comments. Remove the parenthetical.
| * 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: |
| @@ -0,0 +1,47 @@ | |||
| /** | |||
| * Request-scoped hand-off of SEO panel data from the entry query to the | |||
| * render components (#1518). | |||
There was a problem hiding this comment.
[needs fixing] This module-level docstring references #1518. AGENTS.md prohibits issue/PR numbers in comments. Remove the reference.
| * render components (#1518). | |
| * render components. | |
| * | |
| * The loader's single-entry path already folds the `_emdash_seo` row into |
| * 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)", () => { |
There was a problem hiding this comment.
[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.
| * 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 () => { |
There was a problem hiding this comment.
[needs fixing] This test name includes #1518. AGENTS.md prohibits issue references in code, including test identifiers. Remove the reference.
| 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 () => { |
There was a problem hiding this comment.
[needs fixing] This test name includes #1518. AGENTS.md prohibits issue references in code, including test identifiers. Remove the reference.
| 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 |
There was a problem hiding this comment.
[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.
| 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 |
|
Both findings addressed in 55b9e47: dropped the issue references from the new comments, docstrings, and test names, and the site-settings guide now names |
There was a problem hiding this comment.
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-176The aside correctly names
getEmDashEntry(), but “Astro'sgetLiveEntry()on the EmDash collection” is still ambiguous: the EmDash Astro collection is the internal_emdashcollection, 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:3The 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-145getSeoMeta()still resolves canonical by hand and mishandles protocol-relative panel values — withsiteUrlset, a canonical like//other.example/pagebecomeshttps://example.com//other.example/page. The new automatic overlay path already handles this correctly viaresolveSeoCanonicalUrl(). SincegetSeoMeta()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;
|
Applied both doc suggestions in 8f7e8db: the aside now names only the public helper ( On the third suggestion ( |
There was a problem hiding this comment.
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:
-
getSeoMeta()canonical handling diverges from the new automatic path (packages/core/src/seo/index.ts). The PR's newresolveSeoCanonicalUrl()correctly absolutizes root-relative panel canonicals (e.g./custom-pathbecomeshttps://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>orgetSeoMeta(). ReusingresolveSeoCanonicalUrl()ingetSeoMeta()fixes it. -
Changeset overclaims collection support (
.changeset/emdashhead-seo-panel.md). The overlay is only primed in the loader's single-entry (loadEntry) path and in thegetEmDashEntry()object-cache revive path. Entries rendered from multi-entrygetEmDashCollection()/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. -
buildSeoImageUrl()doesn't handle protocol-relative URLs (packages/core/src/seo/media-url.ts). The new siblingresolveSeoCanonicalUrl()treats//host/pathas already-qualified, butbuildSeoImageUrl()treats it as a bare media id and produces a broken doubled-path URL. Returning protocol-relative references unchanged (or rejecting them, asabsolutizeMediaUrl()does) would keep the two resolvers consistent.
All three are fixable with small, safe edits.
Findings
-
[needs fixing]
packages/core/src/seo/index.ts:154The manual fallback canonical resolver still returns root-relative panel values unchanged when
siteUrlis set, while the new automatic overlay path (resolveSeoCanonicalUrl()) correctly absolutizes them. The same panel value now yieldshttps://example.com/custom-pathvia<EmDashHead>but/custom-pathviagetSeoMeta(), 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:9The overlay is only primed on the loader's single-entry (
loadEntry) path and in thegetEmDashEntry()object-cache revive path. Multi-entry collection results fromgetEmDashCollection()/getLiveCollection()do not fold_emdash_seoand 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:17buildSeoImageUrl()treats protocol-relative references (//cdn.example.com/x.png) as bare media ids and produces a broken doubled-path URL. The newresolveSeoCanonicalUrl()next to it correctly recognizes//host/pathas already qualified; the image resolver should do the same, or reject protocol-relative input likeabsolutizeMediaUrl()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; }
… the EmDashHead overlay
|
Addressed the latest review in e98bada:
Full suite green (6456 tests), lint clean, query-count snapshots unchanged. |
There was a problem hiding this comment.
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:
getSeoMeta()canonical handling now delegates toresolveSeoCanonicalUrl(), so a root-relative panel canonical (/custom-path) resolves to the same absolute URL as the<EmDashHead>overlay path.- The changeset no longer overclaims collection coverage and explicitly notes that multi-entry collection results (
getEmDashCollection()) are not covered. buildSeoImageUrl()now treats protocol-relative image references (//cdn.example.com/x.png) as already-qualified, consistent withresolveSeoCanonicalUrl().
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.
ascorbic
left a comment
There was a problem hiding this comment.
Thanks for the extra work on this! Aside from the failing test, this is ready to go.
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_seorow into the entry query as a JSON subselect. This PR primes a request-scoped cache from that folded data at the moments it materializes:getEmDashEntry, so warm cache hits (where the loader never runs) behave identically to cold ones.<EmDashHead>— and the body fragment components, sopage:fragmentshooks 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), soseo.titlefeedsog: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 usinggetSeoMeta()— documented in the site-settings guide.Closes #1518
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
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).