Skip to content

fix(core): prepare seeded media usage - #2472

Open
khoinguyenpham04 wants to merge 2 commits into
feature/media-usage-used-in-uifrom
chore/media-usage-dev-seed-readiness
Open

fix(core): prepare seeded media usage#2472
khoinguyenpham04 wants to merge 2 commits into
feature/media-usage-used-in-uifrom
chore/media-usage-dev-seed-readiness

Conversation

@khoinguyenpham04

@khoinguyenpham04 khoinguyenpham04 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes two problems that made local seeded Media Usage demos misleading:

  • $media seed values now store the ID of the media-library row that was actually created, instead of a separate temporary storage ID;
  • the development-only setup bypass prepares Media Usage data for collections whose sample content was newly created or updated, so Used in is ready when the local admin opens.

The preparation runs only from the development bypass, only after seeded content changed, and does not activate incremental capture. Schema-only setup with ?content=0 remains unchanged. Production activation is still controlled by #2445.

This PR is stacked directly on #2470 and should be reviewed relative to feature/media-usage-used-in-ui.

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 (not applicable; no admin UI strings are added)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: not applicable; this fixes existing seed and development setup behavior

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI Codex (GPT-5.6)

Screenshots / test output

No visual changes.

Verified locally after restacking on #2470:

  • 13 focused dev-bypass and seed-media tests passed;
  • core typecheck and type-aware repository lint passed;
  • repository formatting passed;
  • the complete package workspace build passed;
  • Changesets validation passed;
  • the rebased follow-up has the same stable patch ID as the reviewed pre-restack commit.

Try this PR

Open a fresh playground →

A full working EmDash site, deployed from this branch. Each visit gets its own session-scoped sandbox: no login needed and no shared state. Try the admin, edit content, hit the public site.

Tracks chore/media-usage-dev-seed-readiness. Updated automatically when the playground redeploys.

@changeset-bot

changeset-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c1b3d8e

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

This PR includes changesets to release 17 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/plugin-mcp-smoke 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 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

@khoinguyenpham04
khoinguyenpham04 marked this pull request as ready for review August 14, 2026 15:48
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-do c1b3d8e Aug 15 2026, 11:49 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground c1b3d8e Aug 15 2026, 11:49 PM

@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 14, 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, solving the right problems.

The PR addresses two specific, linked issues in the seeded-media / dev-bypass path: seed $media references were saving the storage-key ULID as the MediaValue id instead of the actual media row id, and the dev-bypass had no step to populate the Media Usage index for freshly seeded sample content, so local demos opened to empty "Used in" data.

I checked:

  • packages/core/src/seed/apply.tsresolveMedia now mints a separate storageId for the storage key and uses media.id for the returned MediaValue.id. This correctly binds seed image/file references to the media-library row.
  • packages/core/src/astro/routes/api/setup/dev-bypass.ts — after applySeed, it repairs Media Usage only when includeContent is true and at least one content row was created or updated, and only for collections present in the seed. It does not touch incremental capture activation.
  • packages/core/src/media/usage/content-repair.ts — the existing collection repair utility is invoked; it works in non-identity mode while activation state is expanded (the default), so the post-seed repair matches the "no incremental capture" constraint.
  • Tests — seed/media.test.ts now asserts id equals media.id, directly verifying the storage-vs-row ID fix. setup-dev-bypass.test.ts adds a regression test that the bypass leaves Media Usage ready and activation in expanded.
  • AGENTS.md conventions — no new queries are added to any logged-out hot path (this is a dev-only setup route). Kysely usage is safe (validateIdentifier for collection slug). The changeset is user-facing and present-tense.

No blocking issues or AGENTS.md violations found. The implementation is minimal, gated correctly, and the tests cover both the ID fix and the bypass readiness fix.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-review No maintainer or bot review yet labels Aug 14, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 14, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache c1b3d8e Aug 15 2026, 11:50 PM

@pkg-pr-new

pkg-pr-new Bot commented Aug 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: c1b3d8e

@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 the rebased branch. The diff matches the previously approved patch: seed $media now stores the actual media row id in MediaValue.id while keeping the storage key under meta.storageKey, and the dev-only setup bypass repairs the Media Usage index for any seeded content collections after applySeed completes.

I re-checked:

  • packages/core/src/seed/apply.tsresolveMedia mints a separate storageId for the storage key and uses media.id for the returned value. The local provider’s getEmbed already prefers meta.storageKey, so file URLs continue to resolve to the uploaded object while MediaValue.id correctly points at the library row.
  • packages/core/src/astro/routes/api/setup/dev-bypass.ts — the repair loop is gated on includeContent, seed validation passing, and at least one content row created or updated. It only touches collections present in the seed and throws if repair does not complete, which is appropriate for a dev-only setup route.
  • packages/core/src/media/usage/content-repair.ts — in the default expanded activation state this runs in non-identity mode, so incremental capture is not activated.
  • Tests — seed/media.test.ts asserts MediaValue.id equals the created media row, and setup-dev-bypass.test.ts verifies the usage index is ready while activation remains expanded.
  • AGENTS.md conventions — no logged-out hot-path changes, no new interpolated SQL (validateIdentifier is used), changeset is present-tense and user-facing.

No regressions or AGENTS.md violations surfaced on the re-read. The branch is ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants