Skip to content

fix(core): refresh cached pages after taxonomy edits - #3338

Merged
ascorbic merged 4 commits into
mainfrom
fix/tag-only-publish-changes
Sep 24, 2026
Merged

ascorbic merged 4 commits into
mainfrom
fix/tag-only-publish-changes

Conversation

@khoinguyenpham04

@khoinguyenpham04 khoinguyenpham04 commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes tag and category edits leaving cached public pages stale. Term assignments already save immediately; the content publish route purged the public cache, but the term-assignment route did not. It now invalidates collection, translation-entry, and taxonomy-facet cache tags after a successful assignment, batching large purges. The admin explains that term changes do not wait for Publish changes, without promising that a term lacking a locale translation appears on every published page.

The previous draft-taxonomy implementation has been reverted. Publish changes still applies to content drafts, not immediate tag edits. This is the narrow bug fix from the team chat; bulk tagging remains a separate request. There is no GitHub issue to close.

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) — 35 targeted core and 81 admin browser tests pass
  • 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). No messages.po changes are included.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: not applicable; this is a bug fix
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI Codex (exact model identifier not exposed in this session)

Screenshots / test output

Published A Weekend with a Side Project post in demos/simple, 1440 × 900, English, light theme. The content field is unchanged in both screenshots.

Before: Creativity is assigned; the post is published.

Published post with only the Creativity tag and no pending content changes

After: Tools is assigned immediately, while the post remains published with no pending content draft. The success toast explains that term changes do not wait for Publish changes.

Published post with Tools and Creativity tags and the Unpublish Post action still visible

pnpm build, pnpm typecheck, pnpm lint, pnpm lint:quick, and pnpm --silent lint:json (zero diagnostics) pass. Focused route tests cover affected translations, taxonomy facets, and the 100-tag purge limit. Manually checked immediate updates and Arabic RTL layout in the running demo. A persistent second-opinion adversarial review converged with no findings.

@changeset-bot

changeset-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 17c9d9a

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

This PR includes changesets to release 12 packages
Name Type
emdash Patch
@emdash-cms/admin Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 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 added the bot:review Trigger an emdashbot code review on this PR label Sep 23, 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 PR fixes the taxonomy-only publishing gap by storing staged tag/category assignments inside the draft revision (_taxonomyDrafts) and promoting them together with the next content publish. The approach fits EmDash's revision model, keeps direct API clients backward-compatible (they simply omit stage), handles translation groups correctly, and updates the admin's invalidation paths so tag-only edits now surface Publish changes.

I read the diff, the changed admin/backend files, and the relevant AGENTS.md conventions. The implementation is solid for the happy path and the regression tests cover staging, publishing, discarding, and D1 rollback. The docs and REST API reference are accurate, and the new UI strings are Lingui-wrapped.

One real issue remains: ContentRepository.publish introduces a multi-statement write (promote the content row, then DELETE/INSERT tag assignments). The D1 path uses executeAtomicBatchIfSupported, but the SQLite/Postgres fallback executes those statements sequentially without a transaction. If a tag assignment statement fails after the promote has succeeded, the content row ends up published while the taxonomy changes are only partially applied. The reconciliation logic only checks the content row, so it can even report success. The fix is to wrap the fallback in withTransaction(this.db, ...), matching the pattern already used by restoreDraftRevision. A representative failure test on the fallback adapter should also be added.

Comment on lines +2554 to +2559
} else {
const result = await promote.execute(this.db);
promoted = result.rows.length === 1;
if (promoted) {
for (const write of taxonomyWrites) await write.execute(this.db);
}

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 taxonomy-promotion fallback runs the content promote UPDATE and the taxonomy DELETE/INSERT statements without a transaction. On adapters that don't support atomic batches (SQLite/Postgres) a failure after promote succeeds leaves the entry published with only some of its tag/category changes applied. The reconciliation code then only inspects the content row, so it can treat the operation as successful.

Wrap the fallback in a transaction, using the same withTransaction pattern already used by restoreDraftRevision in this file and adding a failure test for the non-atomic adapter path.

Suggested change
} else {
const result = await promote.execute(this.db);
promoted = result.rows.length === 1;
if (promoted) {
for (const write of taxonomyWrites) await write.execute(this.db);
}
} else {
await withTransaction(this.db, async (trx) => {
const result = await promote.execute(trx);
promoted = result.rows.length === 1;
if (promoted) {
for (const write of taxonomyWrites) await write.execute(trx);
}
});
}

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 750 lines across 16 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@pkg-pr-new

pkg-pr-new Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@3338

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@3338

@emdash-cms/registry-moderation

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

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 17c9d9a

@cloudflare-workers-and-pages

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
docs 29eb39f Sep 23 2026, 05:05 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://fix-tag-only-publish-changes.try.emdashcms.com, https://fix-tag-only-publish-changes-emdash-playground.emdash-cms.workers.dev (commit 17c9d9a)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://67cf34da.try.emdashcms.com, https://67cf34da-emdash-playground.emdash-cms.workers.dev 17c9d9a 2026-09-23T20:15:25.674Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://a0ea4738.try.emdashcms.com, https://a0ea4738-emdash-playground.emdash-cms.workers.dev 29eb39f 2026-09-23T17:08:24.931Z Visit the dashboard ↗

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

@khoinguyenpham04 khoinguyenpham04 changed the title fix(admin): publish tag-only edits as content drafts fix(core): refresh cached pages after taxonomy edits Sep 23, 2026
@github-actions github-actions Bot added size/M review/needs-rereview New commits since the last review and removed size/XL review/awaiting-author Reviewed; waiting on the author to respond labels Sep 23, 2026
@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Sep 23, 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 re-review confirms the previous draft-taxonomy concern is gone. The PR now takes the narrower, architecture-consistent fix: term assignments still save immediately, the term-assignment route purges the public edge-cache tags that published pages use, and the admin toast explains that term changes do not wait for Publish changes.

I re-read the diff, the changed route/handler/component files, the new ContentRepository.findTranslationIds, and the added tests against the AGENTS.md conventions. The approach looks right: the reverted staging draft avoided conflating content and term lifecycles, and the cache invalidation stays symmetrical with the existing publish / content-update routes.

What I checked:

  • Cache tags: The invalidated tags (collection, canonical + sibling entry IDs, taxonomyTag(...)) match the cacheHint tags emitted by loader.ts for collection lists, entries, and taxonomy facets.
  • Batching: Large translation groups are chunked at MAX_CACHE_PURGE_TAGS = 100, mirrored by an integration test that asserts no batch exceeds 100 tags.
  • SQL safety: findTranslationIds uses ${sql.ref(tableName)} and a parameterized translationGroup value, with the existing deleted_at IS NULL filter.
  • Localization: The new admin description is wrapped in Lingui t; no messages.po changes are included.
  • Authorization: The POST route still checks content:edit_own plus ownership, and cache.invalidate is gated on cache?.enabled like the existing publish route.
  • Changeset: The .changeset/lively-tags-cache.md entry is user-facing, names the observable behavior and the editor clarification, and skips implementation mechanics.
  • Logged-out query counts: No new queries are added to any logged-out route.
  • Prior finding: ContentRepository.publish is no longer touched by this PR, so the non-atomic taxonomy-promotion fallback from the previous review has been removed along with the staging implementation.

No new blocking issues or regressions remain. The added tests cover the actual behavior (cache invalidation with translation siblings, batch sizing, and the toast copy) rather than asserting the implementation back at itself. LGTM.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 23, 2026
@khoinguyenpham04 khoinguyenpham04 mentioned this pull request Sep 23, 2026
11 of 18 tasks
@github-actions github-actions Bot added the review/approved Approved; no new commits since label Sep 23, 2026
@github-actions github-actions Bot removed the review/needs-rereview New commits since the last review label Sep 23, 2026
@ascorbic
ascorbic merged commit ecef5a9 into main Sep 24, 2026
55 checks passed
@ascorbic
ascorbic deleted the fix/tag-only-publish-changes branch September 24, 2026 14:27
@emdashbot emdashbot Bot mentioned this pull request Sep 24, 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.

2 participants