Skip to content

fix(core): sync non-translatable fields when an entry is published - #3090

Merged
ascorbic merged 3 commits into
emdash-cms:mainfrom
danielmlr:fix/non-translatable-sync-on-publish
Sep 13, 2026
Merged

ascorbic merged 3 commits into
emdash-cms:mainfrom
danielmlr:fix/non-translatable-sync-on-publish

Conversation

@danielmlr

@danielmlr danielmlr commented Sep 12, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Syncs non-translatable fields to an entry's other locales when it is published, on collections with revisions, which is the default. A save there only stages a draft, and publishing promoted that draft without running the sync, so the other locales kept their old values.

The sync now runs at publication through ContentRepository.syncNonTranslatableFields, which also replaces the raw UPDATE on the save path of collections without revisions:

  • Only the values the publication changed are copied, so publishing a translation that never held a shared value, or one whose value fell behind while the sync was missing, leaves the other locales' values alone.
  • A locale that already holds every value is not written, so its updated_at, which the sitemap's <lastmod> reads, moves only when its live content changes.
  • A changed locale gets a new version and updated_at, so a _rev read before the sync is refused instead of overwriting the synced value.
  • On collections with revisions it also gets a new live revision, because republishing and unpublishing read that revision rather than the columns.
  • A pending draft in another locale takes a value only where it still holds the previous one, so an unpublished edit to that field survives and syncs when that locale is published.
  • Media usage for the other locales is refreshed after a publish, as it already was after a save.

Saving a draft still leaves the other locales and their updated_at alone (#2143), and hooks fire for the published entry only, as with the save-path sync. A locale that another editor holds the lock on (#2919) is still written, so an open translation never holds back publishing elsewhere, and the version bump turns that editor's next save into a conflict. On D1 the sync is not atomic with the publication, like the slug redirect written after it; the publication itself is still one content-row statement, so the handleContentPublish docstring keeps its opening sentence from #2349. The internationalization guide now says the copy happens at publication.

Closes #2911

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. (n/a: no admin UI change)
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/... (n/a: bug fix)
  • I have included screenshots below if this PR changes the UI (n/a: no UI change)

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5

Screenshots / test output

Not applicable, no UI change.

non-translatable-sync.test.ts covers both kinds of collection on SQLite and PostgreSQL. Seven of its eleven cases fail on main; the other four pin what the fix must leave alone. The cases for a matching locale, the new live revision, a pending draft and an unchanged or missing value each fail when that part is removed, run one mutation at a time. Both new cases in media-usage-runtime-refresh.test.ts fail without the runtime change. The full packages/core suite passes.

Fails on main. On a collection with revisions a save stages a draft and the
publish path never syncs, so the other locales keep their old values. On a
collection without revisions the sync runs, but it rewrites the other
locales without advancing their version, so a `_rev` read before the sync
still validates and a stale save overwrites the synced value.

The remaining cases pin what a fix has to preserve: a pending draft in
another locale keeps a value it changed on its own, republishing or
unpublishing that locale keeps the synced value, and a locale that already
holds the value is not touched. A publication copies only the values it
changed, so publishing a translation that never held a shared value, or
one whose value fell behind, leaves the other locales' value alone. Media
usage for the other locales has to follow a publish the way it already
follows a save, a cleared image included.
Publishing is where a draft's values reach the content columns, so it is
now where they reach the other locales too. The sync moves into
`ContentRepository.syncNonTranslatableFields`, called by the publish
handler on collections with revisions and by the update path on
collections without them.

At publication it copies only the values the publication changed,
compared with the entry's row before it, so publishing a translation that
never held a shared value, or one whose value fell behind, does not
overwrite the other locales. For every other entry in the translation
group it:

- skips the entry when it already holds every value, so its `updated_at`,
  which feeds sitemap `<lastmod>` and `dateModified`, moves only when its
  live content does;
- writes the changed columns and advances `version` and `updated_at`, so a
  `_rev` read before the sync is refused;
- on collections with revisions, points `live_revision_id` at a new revision
  carrying the synced values, because republishing and unpublishing read
  that revision rather than the columns;
- carries a value into a pending draft only where the draft still holds the
  entry's previous value, so an unpublished edit to the field survives and
  syncs once that locale is published.

The write is a compare-and-swap on `version` and both revision pointers,
retried against a fresh read the way draft staging is. Trashed entries are
still synced, as before, and so is an entry another editor holds the lock
on; the version bump turns that editor's next save into a conflict.

After a publish the runtime refreshes media usage for the other locales,
as it already did after a save on a collection without revisions. The
published entry's data leaves out NULL columns, so that lookup counts an
absent non-translatable field as cleared; otherwise an image the
publication cleared would stay recorded as used by the other locales.
@changeset-bot

changeset-bot Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6596a10

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

This PR includes changesets to release 18 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@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 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/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

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 681 lines across 8 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 12, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-test

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

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-moderation

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

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 6596a10

@danielmlr
danielmlr marked this pull request as ready for review September 13, 2026 00:20
@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Sep 13, 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 fix for the described bug. Moving non-translatable field sync from the save path to the publish path (for revision-enabled collections) matches the product model where a draft save should not propagate to other locales. The implementation is careful: it only copies values that actually changed, preserves per-locale updated_at for unchanged siblings, bumps version so stale _rev writes fail, creates new live revisions on revision collections so republish/unpublish stay consistent, and carries synced values into a draft only when the draft hadn’t diverged on that field. Media-usage refresh is wired into the publish path with the absentAsCleared option so clearing a non-translatable image on publish still refreshes siblings.

I read the full diff, the changed handler/repository/runtime files, the transaction.ts helper (which explains the documented D1 non-atomicity), the RevisionRepository, and the new/updated tests. SQL is parameterized and identifiers are validated. The tests are integration-level and exercise the exact regressions/fixed behaviors described. The changeset and docs paragraph are user-facing and accurate.

I have only one minor suggestion: the handleContentPublish docstring still opens with “Publication is one atomic content-row statement,” which is misleading now that the handler also runs the locale sync and slug redirect. Rephrasing the opening sentence keeps the docstring from contradicting the rest of the description. With that addressed or accepted, this looks ready to merge.

@@ -1649,6 +1648,21 @@ export async function handleContentPublish(
expectedRevision,
);

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 docstring still says "Publication is one atomic content-row statement," but the handler now performs the publish, the non-translatable locale sync, and the slug redirect. The second sentence already notes the side writes, so the opening line contradicts the rest of the comment.

Suggested change
);
/**
* Publish content immediately.
*
* Promotes the staged draft to live and runs any non-translatable field sync
* and slug-redirect side writes. On databases that support transactions,
* the publication, sync, and redirect stay grouped atomically.
*/

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.

I'm leaving this sentence as it is. It comes from #2349, not this PR, and it describes the publication statement itself: that one content-row write is why a publish stays atomic on D1, where the locale sync and the slug redirect run after it without a transaction. The second sentence refers back to it. The suggested wording drops that, and a collection without revisions has no staged draft to promote.

@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 and removed review/needs-review No maintainer or bot review yet labels Sep 13, 2026
@ascorbic
ascorbic merged commit e13fa01 into emdash-cms:main Sep 13, 2026
65 checks passed
@danielmlr
danielmlr deleted the fix/non-translatable-sync-on-publish branch September 13, 2026 10:57
@emdashbot emdashbot Bot mentioned this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core area/docs review/awaiting-author Reviewed; waiting on the author to respond size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-translatable fields never sync to sibling locales on collections that support revisions

2 participants