You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
This leads to another error when trying to do a payload.update():
CastError: Cast to embedded failed for value "{...}" (type Object) at path "blocks" because of "CastError"
at model.Query.exec (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/mongoose/lib/query.js:4921:21)
at Query.then (webpack-internal:///(rsc)/./node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_/node_modules/mongoose/lib/query.js:5020:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
In the error message:
{...} is the entire content of the document — I've removed it for brevity
"blocks" is the name of a field of type blocks in the document
I think this cast error refers to the fact that Payload attempts to slide in the object { "en": "..." } into a field that expects a string:
When the field has localize: true, it's an object with each locale as the key
When localize: true is removed, it is now expected to be a string
The object still remains in the database
When performing an update, even on a completely unrelated field, Payload uses the current value (the object), when a string is expected
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.git
pnpm docker
to start the projecthttp://localhost:3000/admin/collections/pages
slug
:foo
text
:hello
LOCALIZED=true
in.env
text
field tohello2
LOCALIZED=true
from.env
[object Object]
(not expected)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:"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
"foo"
{ "en": "foo" }
bg
"foo"
"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
"foo"
{ "en": "foo" }
bg
"foo"
{ "bg": "фуу" }
bg
""
…but the current behavior is this:
"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
"foo"
{ "en": "foo" }
bg
"foo"
"foo"
en
"foo"
"foo"
bg
"foo"
{ "en": "foo" }
en
{ "en": "foo" }
{ "en": "foo" }
bg
{ "en": "foo" }
{ "bg": "фуу" }
bg
{ "bg": "фуу" }
Which area(s) are affected? (Select all that apply)
area: core
Environment Info
The text was updated successfully, but these errors were encountered: