craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

Fix serializeNodes when props are undefined / null

Open tomgidden opened this issue 3 years ago • 4 comments

We're getting the error

index.js:362 TypeError: Cannot convert undefined or null to object
    at keys (<anonymous>)
    at Function.keys (es5-shim.js:1312)
    at serializeComp (index.js:1111)
    at index.js:1125
    at Array.reduce (<anonymous>)
    at serializeComp (index.js:1111)
    at serializeNode (index.js:1140)
    at Object.toSerializedNode (index.js:1288)
    at index.js:1387
    at Array.map (<anonymous>)

which appears to occur when props for an element (or a node within an element) is null or undefined, rather than {}. I'm not sure exactly why this is happening at this point, but this seems to fix it.

tomgidden avatar Aug 20 '20 11:08 tomgidden

Deploy preview for craftjs ready!

Built with commit 9b93e10be21ae57e31d54b1d4c16f93b49004eee

https://deploy-preview-118--craftjs.netlify.app

netlify[bot] avatar Aug 20 '20 11:08 netlify[bot]

Hi guys when can you fix it ?

flavienrako avatar Nov 11 '20 21:11 flavienrako

According to our TS interface and how craft was setup to work 'props' is not optional and should not be missing when serializing a node, and in such case i'm not sure if this PR is actually fixing the root issue here or just acting as a band-aid 🤔

matdru avatar Nov 11 '20 21:11 matdru

Like what @matdru said, this error shouldn't have occurred in the first place, which suggests an underlying problem that we are not looking at.

@tomgidden @flavienrako Does this issue this still happen in the latest version of Craft (0.1.0-beta.13)? If it does, could you share an example for us to reproduce the bug? Thanks!

prevwong avatar Nov 12 '20 03:11 prevwong