Describe the bug
When opening an existing page in admin, the corresponding custom preview component crash with the following error:
index.js:2177 Invariant Violation: Objects are not valid as a React child (found: Wed Jul 10 2019 10:04:46 GMT+0200 (Central European Summer Time)). If you meant to render a collection of children, use an array instead.
To Reproduce
(not sure this is the exact steps to reproduce)
You can find my project for reproduction here: https://github.com/bonitasoft-labs/talks/tree/f5509f2f933ce6531204d7bc93d07ca9928be23b
Incriminated files:
Expected behavior
Widget initial value should be consistent with the one in the markdown of a page.
Screenshots
Production build:
Unminified:
Applicable Versions:
CMS configuration
https://github.com/bonitasoft-labs/talks/blob/f5509f2f933ce6531204d7bc93d07ca9928be23b/static/admin/config.yml
Additional context
After commenting the {date}
rendering line, it makes the error disappear.
Using the React inspector, we can see that the date
input value is a datetime:
but this is not the case when we create a new page
It looks like the previous value was kept somehow, but I can't find why and where. FYI, I already did a git reset --hard && git clean -dfx
to be sure.
Following #1666, if I use entry.getIn(['data', 'date']).toString()
, we can see that the initial data is indeed a datetime:
but if we edit this value, a real date is given
Ok, I think I found the issue here.
I fixed it by:
a. deleting all branches which have been automatically generated by the CMS and then merged
b. edit the "date" format in markdown from "2019-07-10" to "Jul 10th 19" https://github.com/bonitasoft-labs/talks/pull/19/files
I had misunderstood the date format https://github.com/bonitasoft-labs/talks/blob/4fb8034938f4e222b0dcd768c0c2f2f684fd2aef/static/admin/config.yml#L19 here. My bad.
So, in order to be clear and help anyone who would encounter the same issue, here are the gotcha:
MMM, Do YY
) to iso (YYYY-MM-DD
), you have to add single quotes in your markdown (date: '2019-07-10'
).None of this is really a bug :man_shrugging: Just keep an eye on what Netlify CMS generates and expect if you want to directly edit your markdowns.
Thank you @noelmace. We had a similar problem where date picker's output was a date object rather a string, which produced React error#31. We finally solved it making sure the date attached to all posts had single quotes(ex: ''2020-05-23') and changing our config.yml so the line regarding date looked like
- { label: Date / Order, name: date, widget: date, format: 'YYYY-MM-DD' }
Most helpful comment
So, in order to be clear and help anyone who would encounter the same issue, here are the gotcha:
MMM, Do YY
) to iso (YYYY-MM-DD
), you have to add single quotes in your markdown (date: '2019-07-10'
).None of this is really a bug :man_shrugging: Just keep an eye on what Netlify CMS generates and expect if you want to directly edit your markdowns.