-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Closed as not planned
Labels
Description
Describe the Bug
When you remove a field that has previously had localized: true and a value in the database, the front-end breaks.
Link to the code that reproduces this issue
https://github.com/hdodov/test-payload/tree/localize-issues
Reproduction Steps
git clone [email protected]:hdodov/test-payload.gitpnpm dockerto start the project- Open
http://localhost:3000/admin/collections/pages - Create a page with the fields:
slug:footext:hello
- You'll see this in the database:
{ "_id" : ObjectId("672efe5985ce4bd7437d6d7c"), "slug" : "foo", "text" : "hello", "createdAt" : ISODate("2024-11-09T06:16:57.505+0000"), "updatedAt" : ISODate("2024-11-09T06:16:57.505+0000"), "__v" : NumberInt(0) } - Add
LOCALIZED=truein.env - Restart the server
- Change the
textfield tohello2 - You'll get this in the database:
{ "_id" : ObjectId("672efe5985ce4bd7437d6d7c"), "slug" : "foo", - "text" : "hello", + "text" : { + "en" : "hello2" + }, "createdAt" : ISODate("2024-11-09T06:16:57.505+0000"), "updatedAt" : ISODate("2024-11-09T06:36:22.517+0000"), "__v" : NumberInt(0) } - The admin and the page still work as expected
- Remove
LOCALIZED=truefrom.env - Restart the server
- Data remains the same in the database (expected)
- Field value in the admin changes to
[object Object](not expected)

- There's the following error on the front-end (not expected):
Error: Objects are not valid as a React child (found: object with keys {en}). If you meant to render a collection of children, use an array instead. at throwOnInvalidObjectType (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:4419:13) at reconcileChildFibersImpl (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:5356:11) at eval (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:5398:33) at reconcileChildren (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:7721:13) at beginWork (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:9934:13) at runWithFiberInDEV (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:544:16) at performUnitOfWork (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:14997:22) at workLoopSync (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:14827:41) at renderRootSync (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:14807:11) at performWorkOnRoot (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:14342:44) at performWorkOnRootViaSchedulerTask (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/react-dom/cjs/react-dom-client.development.js:15853:7) at MessagePort.performWorkUntilDeadline (webpack-internal:///(app-pages-browser)/./node_modules/.pnpm/[email protected][email protected][email protected]__react@19_7kfqem4pd6aim6nxuy4v6dxrry/node_modules/next/dist/compiled/scheduler/cjs/scheduler.development.js:44:48)
Proposed Solution
Payload should check if fields are coming in the form of an object from the database. It already normalizes { en: "content" } to "content" when the field is marked as localized. It just has to do this when the field is not marked as localized too. In other words, it should function like this:
| Field is localied | Database value | Requested locale | Returned value |
|---|---|---|---|
| Yes | "foo" |
en |
"foo" |
| Yes | "foo" |
bg |
"foo" |
| Yes | { "en": "foo" } |
en |
"foo" |
| Yes | { "en": "foo" } |
bg |
"foo" |
| No | "foo" |
en |
"foo" |
| No | "foo" |
bg |
"foo" |
| No | { "en": "foo" } |
en |
"foo" |
| No | { "en": "foo" } |
bg |
"foo" |
| No | { "bg": "фуу" } |
bg |
"" |
…but the current behavior is this:
| Field is localied | Database value | Requested locale | Returned value |
|---|---|---|---|
| Yes | "foo" |
en |
"foo" |
| Yes | "foo" |
bg |
"foo" |
| Yes | { "en": "foo" } |
en |
"foo" |
| Yes | { "en": "foo" } |
bg |
"foo" |
| No | "foo" |
en |
"foo" |
| No | "foo" |
bg |
"foo" |
| No | { "en": "foo" } |
en |
{ "en": "foo" } |
| No | { "en": "foo" } |
bg |
{ "en": "foo" } |
| No | { "bg": "фуу" } |
bg |
{ "bg": "фуу" } |
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
Binaries:
Node: 20.17.0
npm: 10.8.2
Yarn: N/A
pnpm: 9.9.0
Relevant Packages:
payload: 3.0.0-beta.126
next: 15.0.0
@payloadcms/db-mongodb: 3.0.0-beta.126
@payloadcms/email-nodemailer: 3.0.0-beta.126
@payloadcms/graphql: 3.0.0-beta.126
@payloadcms/next/utilities: 3.0.0-beta.126
@payloadcms/payload-cloud: 3.0.0-beta.126
@payloadcms/richtext-lexical: 3.0.0-beta.126
@payloadcms/translations: 3.0.0-beta.126
@payloadcms/ui/shared: 3.0.0-beta.126
react: 19.0.0-rc-65a56d0e-20241020
react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64
Available memory (MB): 32768
Available CPU cores: 16
shaferova, todor0v, stananiev, yordanoff and truuman