Open rbruels opened 1 week ago
Hi @rbruels ,
I've encountered this same error when using just an empty array as a JSON field value. []
.
I think it may be an admin visual parsing error that happens when the field contains an Array.
I'll see if this is connected.
Hi @kendelljoseph — it definitely occurs when the value is a JSON array with multiple elements. We discovered it because our JSON field had an array with >100 elements. See my diagnosis above:
The problematic code is here:
https://github.com/payloadcms/payload/blob/beta/packages/ui/src/elements/Table/DefaultCell/fields/JSON/index.tsx#L11
In this case, cellData is a json array. So cellData.length > 100 is valid code ... but when the # of objects in the array exceeds 100, it calls cellData.substring which is not valid for the array.
Yep. I have reproduced it on my end. They are connected. The cellData can also be an array, and arrays don't have the substring property.
I should have a fix for this ready soon!
Rad!! Now we just need work on migrating to 3.0 😅 Thanks @kendelljoseph
Describe the Bug
The collection list view crashes if the collection has a
JSON
field which contains an array with greater than 100 items.The error is:
Link to the code that reproduces this issue
https://github.com/rbruels/payload-json-issue
Reproduction Steps
Add json field
I just added this to the default
Media
collection:Insert data
Insert a new
Media
object and add an image/alt text and then in the newdata
field, add a json array exceeding 100 items. You can copy paste this if you're so inclined:Save the object.
Reload the list view
Go back to the list view for media (http://localhost:3000/admin/collections/media)
You'll immediately see an error:
The problematic code is here:
https://github.com/payloadcms/payload/blob/beta/packages/ui/src/elements/Table/DefaultCell/fields/JSON/index.tsx#L11
In this case,
cellData
is a json array. SocellData.length > 100
is valid code ... but when the # of objects in the array exceeds 100, it callscellData.substring
which is not valid for the array.Which area(s) are affected? (Select all that apply)
area: ui
Environment Info