Objects with no `constructor` fails to render in tree mode
WKBae opened this issue · comments
Code to reproduce
<script>
import { JSONEditor } from 'svelte-jsoneditor';
</script>
<JSONEditor content={{json: Object.create(null)}} />
Cause
Object.create(null)
creates an object with no constructor
set.
estimateSerializedSize
recurses json and tests if one is object with value.constructor.name === 'Object'
, throwing TypeError: Cannot read properties of undefined (reading 'name')
on such objects.
svelte-jsoneditor/src/lib/utils/typeUtils.ts
Lines 9 to 13 in 278dac5
(Related issue: #321)
Parse function of json-bigint creates object with Object.create(null)
, causing the error when used as a custom parser of jsoneditor.
Good point! There is a utility function isObject
that tries to identify whether something is a plain object (and not a Date or Map or class or something). We'll have to refine that function to cater for this case.
Fixed now in v0.21.3