Fix locale-scoped content updates#1302
Conversation
🦋 Changeset detectedLatest commit: da551f2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 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 |
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
This is a solid, well-scoped bug fix. The approach — threading an optional locale through slug resolution so updates target the right row when multiple locales share a slug — is exactly what #1243 calls for, and it fits EmDash's architecture (locale is already optional in findByIdOrSlug, handleContentGet, etc.).
I checked the full diff and traced the locale parameter:
- REST route (
[id].ts): extractslocalefrom query params, passes it tohandleContentGetfor ownership lookup and into thehandleContentUpdatebody. Correct. - Handler (
content.ts):resolveIdnow forwardslocaleto the repository. Correct. - Runtime (
emdash-runtime.ts): useslocalefor the initial slug→ID resolution and passes it through to the handler. Correct. - JS client: appends
localeas a query param on the PUT URL. Correct. - CLI: exposes
--locale, passes it through, and importantly switches follow-uppublish/getcalls to use the resolved concreteupdated.idinstead of the ambiguous slug. Good defensive fix. - MCP server: adds
localeto thecontent_updateinput schema and forwards it. Correct. - Tests: handler, route-permission, client, CLI integration, and MCP integration tests all cover the locale-scoped update scenario. Good coverage.
No logic bugs, security issues, or AGENTS.md violations found. The parameterized Kysely queries in findBySlug are safe, the change is additive/backwards-compatible, and the changeset is present.
One small gap: the OpenAPI document (packages/core/src/api/openapi/document.ts) does not declare the locale query parameter on the updateContent PUT operation. The GET operation on the same path already documents it; the PUT spec should match so API consumers know the parameter exists.
|
I have read the CLA Document and I hereby sign the CLA |
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. |
Co-authored-by: emdashbot[bot] <273199577+emdashbot[bot]@users.noreply.github.com>
@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/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: |
Main's #1302 already added locale reading to the PUT content-update route. Drop this branch's duplicate declaration (kept main's request.url form, which the existing route test exercises) so the merged PUT handler has a single `locale`. The branch's remaining core contribution is locale on DELETE and the publish/unpublish/schedule/ discard-draft sub-action routes.
What does this PR do?
Fixes locale-scoped content updates when callers update by slug and multiple locales share that slug.
This wires
localethrough RESTPUT /content/:collection/:id?locale=..., the core handler/runtime slug resolution, the JS client, CLIcontent update, and MCPcontent_update. The CLI also uses the returned concreteitem.idfor follow-up publish/refetch calls so it does not reuse an ambiguous slug after a locale-scoped update.Closes #1243
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
Non-visual bug fix.
Checks run:
pnpm buildpnpm lint:quickpnpm typecheckpnpm lintpnpm --filter emdash test tests/unit/api/content-handlers.test.ts tests/unit/api/content-route-permissions.test.ts tests/unit/client/client.test.ts tests/unit/mcp/authorization.test.ts tests/integration/mcp/content-misc.test.tspnpm --filter emdash test:integration tests/integration/cli/cli.test.tspnpm formatgit diff --check