Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localized fields in relationship drawer are populated in the default locale, not in the current locale #9979

Closed
felixmokross opened this issue Dec 14, 2024 · 5 comments · Fixed by #10262
Assignees

Comments

@felixmokross
Copy link

felixmokross commented Dec 14, 2024

Describe the Bug

When opening the Relationship drawer, localized fields of the related collection item are populated in the default locale instead of the current locale. Even though the field label correctly shows the current locale code, the value comes from the default locale.

In our application, we heavily rely on relationships with localized content in collections with many items. Therefore, this bug gives us a bit of a headache. We could give the users a workaround if the Relationship field or drawer had a link to the full page of the relationship item (this would generally be a handy feature). But currently, users have to open the drawer, copy the item ID, then go to the related collection and look up the item by ID.

I observed this issue already on 3.0, but was only now able to create a minimal reproduction.

Link to the code that reproduces this issue

https://github.com/felixmokross/payload/tree/locale-bug-repro/test/_community

Reproduction Steps

  1. In the payload config, enable localization and add at least two locales:
// payload config
localization: {
     locales: ['en', 'es'],
     defaultLocale: 'en',
     fallback: true,
 },
  1. Create a collection (A) with a localized field:
export const TextsCollection: CollectionConfig = {
   slug: 'texts',
   admin: {
     useAsTitle: 'text',
   },
   fields: [
     {
       name: 'text',
       type: 'text',
       localized: true,
     },
   ],
}
  1. In another collection (B), add a relationship to the collection (A):
{
       name: 'title',
       type: 'relationship',
       relationTo: 'texts',
}
  1. Create a new item of collection (A). In the localized field, save different values for the locales. E.g.
    en: 'hello'
    es: 'hola'
  2. Create a new item of collection (B). In the relationship field, select the item from collection (A).
  3. In the admin UI, switch to a locale that is not the default locale, e.g. es, while the default locale is en.
  4. Open the Edit view of the newly created collection (B) item.
  5. Click on the Pencil icon in the relationship field.

Observed behavior: The Relationship drawer opens. In the localized field the value is populated in the default locale ('hello'). However, the field's label indicates correctly the current locale.

Expected behavior: In the localized field the value is populated in the current locale ('hola').

Relationship drawer for the collection (A) item:
Image

Edit view of the collection (A) item:
Image

Which area(s) are affected? (Select all that apply)

area: ui

Environment Info

Payload: 3.7.0
Node.js: 20.12.2
Next.js: 15.0.3
@felixmokross felixmokross added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Dec 14, 2024
@gkennedy87
Copy link
Contributor

@felixmokross Have you tried updating your versions of Payload, Next, and Node?

When I tried to reproduce the issue in Payload 3.9.0, it worked as expected.

@felixmokross
Copy link
Author

I just checked with the latest main branch (did a pnpm install) and can still reproduce it. Are you sure you tested with different values per locale on the texts collection? And the bug only occurs on the Relationship Drawer, not on the full Edit View.

To me it seems that getDocumentData and renderDocument do not receive the locale arg. In the renderDocumentHandler it is not passed to the renderDocument function. Just not sure how to get the locale here.

This is from the handleServerFunction, I added the highlighted comment:
Image

The locale on the initPageResult param is the only way how getDocumentData could know the locale, but it is not passed here.

@gkennedy87
Copy link
Contributor

@felixmokross I was able to successfully reproduce this bug. Thanks for your clarification. I missed the step of clicking on the pencil icon in the relation drawer in my initial attempt.

Copy link
Contributor

github-actions bot commented Jan 1, 2025

This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.

Copy link
Contributor

github-actions bot commented Jan 2, 2025

🚀 This is included in version v3.13.0

@github-actions github-actions bot locked and limited conversation to collaborators Jan 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants