payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
24.58k stars 1.56k forks source link

getting `{ [locale]: string }` on fields with `localized: false` while payload-types.ts outputs `string` #8826

Closed GermanJablo closed 2 hours ago

GermanJablo commented 2 hours ago

Describe the Bug

Explained in reproduction steps.

Maybe it's related to the other bug we were talking about localization interfering with searchPlugin @paulpopus?

Link to the code that reproduces this issue

https://github.com/payloadcms/enterprise-demo/tree/localized-type-bug

Reproduction Steps

The repository is based on the website template but localization is added:

  localization: {
    defaultLocale: 'en',
    locales: [
      {
        code: 'en',
        label: 'English',
        rtl: false,
      },
    ],
  },

If you add localized: true to the title field in the posts collection, everything works fine because the type is string, which matches the type in payload-types.ts.

However, if you omit localized: true or set it to false, payload-types.ts still sets it to string, but src/components/Card/index.tsx gets { [locale]: string } and that's why when you try to render {titleToUse} in that file you get this error:

Image

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

area: core, area: templates

Environment Info

Payload: beta.114

GermanJablo commented 2 hours ago

The problem was that I set localized: true, translated the field, and then set localized: false again, so the data was corrupted. Restarting the DB fixed it.