Skip to content

Admin content edit route should preserve locale for slug-based i18n entries #1242

@WellDunDun

Description

@WellDunDun

Summary

In an i18n site, the Admin UI edit route can open the wrong locale variant when the URL identifier is a slug-like ID and another locale shares the same slug.

We hit this in an Astro/Cloudflare EmDash site with pages/about:

  • English row: id: "about", slug: "about", locale: "en"
  • Arabic row: id: "about-ar", slug: "about", locale: "ar", translationOf: "about"

Navigating directly to:

/_emdash/admin/content/pages/about

opened the Arabic row and made it difficult/impossible to select/edit the English row.

What appears to happen

The content list page is locale-aware and defaults to i18n.defaultLocale, but the content edit page does not validate/preserve a locale search param and calls:

fetchContent(collection, id)

which fetches:

/_emdash/api/content/pages/about

without ?locale=en.

Because EmDash permits duplicate slugs across locales, an unscoped slug lookup is ambiguous.

Expected behavior

When i18n is enabled, the Admin content edit route should pass the active locale through to content reads and writes, likely defaulting to manifest.i18n.defaultLocale when no explicit ?locale= is present.

Example:

/_emdash/api/content/pages/about?locale=en

Local workaround

We patched @emdash-cms/admin@0.14.0 locally to:

  • accept locale in the edit route search params
  • compute activeLocale = searchParams.locale ?? i18n.defaultLocale
  • include locale in the single-content query key
  • call fetchContent(collection, id, { locale: activeLocale })
  • pass rawItem.locale ?? activeLocale to update/autosave calls

We also patched the API/runtime side so PUT requests with ?locale= use that locale when resolving slug-like IDs.

Version

Observed on EmDash 0.14.0 / @emdash-cms/admin@0.14.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions