Skip to content

fix(core): hydrate SEO on entries from getEmDashEntry/getEmDashCollection - #612

Closed
drudge wants to merge 9 commits into
emdash-cms:mainfrom
drudge:fix/entry-seo-hydration
Closed

drudge wants to merge 9 commits into
emdash-cms:mainfrom
drudge:fix/entry-seo-hydration

Conversation

@drudge

@drudge drudge commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

entry.data.seo is always undefined when using getEmDashEntry / getEmDashCollection, because the live loader in loader.ts only reads columns from the content table — SEO lives in the separate _emdash_seo table. Today the only paths that attach SEO are the REST handlers (api/handlers/content.ts) and the plugin context, so storefront templates that call getSeoMeta(entry, …) (as the seo/index.ts docstring already suggests) silently get empty values.

This PR adds a hydrateEntrySeo helper in query.ts that mirrors the existing hydrateEntryBylines / hydrateEntryTerms:

  • Early-returns when the collection does not have has_seo = 1.
  • Batch-loads SEO rows via the existing SeoRepository.getMany (no N+1).
  • Attaches each entry's resolved record to entry.data.seo.
  • Swallows "no such table" errors for pre-migration databases (same pattern as bylines/terms).

Wired into both getEmDashEntry (single) and getEmDashCollection (batch). Runs in parallel with the existing byline/term hydration via Promise.all, so the added cost is one extra batched query — only on SEO-enabled collections.

Closes #

Type of change

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

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code

Test output

packages/core/tests/integration/seo/seo-query-hydration.test.ts adds a regression test that mocks astro:content to feed a controlled raw entry shape, then drives the real getEmDashEntry / getEmDashCollection against an in-memory SQLite + SeoRepository. Reverting hydrateEntrySeo flips the positive cases red, so the test guards the fix from regression. Existing tests/integration/seo/seo.test.ts (55 cases) still passes alongside it.

Open question for reviewers

Should SEO hydration be always-on (this PR's choice) or opt-in (e.g. { includeSeo: false } for callers that want to skip the extra query)? The cost is one extra batched query per call — scoped to SEO-enabled collections only — so the blast radius feels small enough to justify always-on, matching the existing byline/term hydration pattern. Happy to gate it either way.

@changeset-bot

changeset-bot Bot commented Apr 16, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 38b51f7

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

This PR includes changesets to release 13 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto 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

…tion

`entry.data.seo` was always undefined because the live loader only reads
columns from the content table — SEO lives in a separate `_emdash_seo`
table. Callers had to manually load it via an internal repo.

Add a `hydrateEntrySeo` helper that mirrors `hydrateEntryBylines`:
checks the collection has SEO enabled, batch-loads via SeoRepository,
and attaches the record at `entry.data.seo`. Called from both
`getEmDashEntry` and `getEmDashCollection`.

This makes `getSeoMeta(entry, ...)` usable directly on the result of
`getEmDashEntry` as the seo/index.ts docstring already shows.
@drudge
drudge force-pushed the fix/entry-seo-hydration branch from 6d68acd to 50607f7 Compare April 24, 2026 14:15
@pkg-pr-new

pkg-pr-new Bot commented Apr 24, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 38b51f7

Mocks `astro:content` to feed a controlled raw entry shape, then
asserts the new `hydrateEntrySeo` helper attaches `entry.data.seo`
when the collection has `has_seo = 1` and skips when it's disabled.
Reverting the hydration call site causes the positive cases to fail —
so this guards the fix from regression.
@github-actions github-actions Bot added size/L and removed size/M labels Apr 27, 2026
@drudge
drudge marked this pull request as ready for review April 27, 2026 15:25
@github-actions github-actions Bot added the query-count changed PR diff modifies query-count snapshot files label Apr 29, 2026
@github-actions

github-actions Bot commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Query-count snapshot changes

32 routes changed, total Δ +96 queries.

SQLite

Route Before After Δ
GET / (cold) 11 14 +3
GET / (warm) 11 14 +3
GET /category/development (cold) 15 18 +3
GET /category/development (warm) 14 17 +3
GET /pages/about (cold) 10 12 +2
GET /pages/about (warm) 10 12 +2
GET /posts (cold) 11 14 +3
GET /posts (warm) 11 14 +3
GET /posts/building-for-the-long-term (cold) 23 30 +7
GET /posts/building-for-the-long-term (warm) 23 30 +7
GET /rss.xml (cold) 4 6 +2
GET /rss.xml (warm) 4 6 +2
GET /search (cold) 12 13 +1
GET /search (warm) 12 13 +1
GET /tag/webdev (cold) 14 17 +3
GET /tag/webdev (warm) 14 17 +3

D1

Route Before After Δ
GET / (cold) 21 24 +3
GET / (warm) 11 14 +3
GET /category/development (cold) 25 28 +3
GET /category/development (warm) 14 17 +3
GET /pages/about (cold) 20 22 +2
GET /pages/about (warm) 10 12 +2
GET /posts (cold) 21 24 +3
GET /posts (warm) 11 14 +3
GET /posts/building-for-the-long-term (cold) 32 39 +7
GET /posts/building-for-the-long-term (warm) 22 29 +7
GET /rss.xml (cold) 13 15 +2
GET /rss.xml (warm) 4 6 +2
GET /search (cold) 22 23 +1
GET /search (warm) 12 13 +1
GET /tag/webdev (cold) 25 28 +3
GET /tag/webdev (warm) 14 17 +3

Comparing snapshot files between base and head. Updated automatically on each push.

@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.

Copilot AI review requested due to automatic review settings April 30, 2026 16:18

Copilot AI 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.

Pull request overview

Fixes missing SEO data on entries returned by the public query wrappers (getEmDashEntry / getEmDashCollection) by hydrating from _emdash_seo, aligning query-wrapper behavior with existing REST/plugin paths.

Changes:

  • Add hydrateEntrySeo() in packages/core/src/query.ts and run it alongside byline/term hydration for both single-entry and collection queries.
  • Add an integration regression test to validate SEO hydration behavior for SEO-enabled vs SEO-disabled collections.
  • Add a changeset documenting the patch release impact.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/query.ts Adds batched SEO hydration (gated by has_seo) and wires it into query wrappers.
packages/core/tests/integration/seo/seo-query-hydration.test.ts New integration test covering SEO hydration through getEmDashEntry/getEmDashCollection.
.changeset/entry-seo-hydration.md Patch changeset describing the hydration fix and user-facing effect.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/query.ts Resolved
Two Copilot comments addressed:

- Reserve `seo` in `RESERVED_FIELD_SLUGS` (matching the existing pattern
  for `terms`/`bylines`/`byline`) so user-defined fields can't shadow the
  hydrated payload, plus parity test in registry.test.ts.

- Switch `seo-query-hydration.test.ts` to `vi.hoisted()` for the
  `astro:content` mock fns, mirroring the documented safe pattern in
  middleware-prerender.test.ts. Avoids a TDZ risk when the `vi.mock`
  factory hoists above the const declarations.
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

@github-actions github-actions Bot added the review/needs-rereview New commits since the last review label May 30, 2026
@github-actions github-actions Bot mentioned this pull request Jun 1, 2026
10 of 18 tasks
@github-actions github-actions Bot added stale and removed stale labels Jun 13, 2026
@github-actions github-actions Bot added stale and removed stale labels Jun 27, 2026
@github-actions github-actions Bot added stale and removed stale labels Jul 15, 2026
@ascorbic

Copy link
Copy Markdown
Member

Thanks for the contribution. I'm going to close this as we've taken a different approach to this.

@ascorbic ascorbic closed this Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core cla: signed needs-rebase query-count changed PR diff modifies query-count snapshot files review/needs-rereview New commits since the last review size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants