DataCloneError saving an object with a function key
arolson101 opened this issue · 2 comments
I'm using dexie-observable
under node.js through fake-indexeddb
. Through a series of events it ends up calling put
on an object with a save
prototype method, which fails because lodash's isPlainObject
returns false:
} else if (!isPlainObject(input)) {
// This is way too restrictive. Should be able to clone any object that isn't
// a platform object with an internal slot other than [[Prototype]] or [[Extensible]].
// But need to reject all platform objects, except those whitelisted for cloning
// (ie, those with a [[Clone]] internal method), and this errs on the side of caution
// for now.
// Supposed to also handle FileList, ImageData, ImageBitmap, but fuck it
throw new DataCloneError();
} else {
According to the structured clone algorithm this should be ok- the object will be duplicated but "The prototype chain does not get walked and duplicated".
For comparison, Chrome's IndexedDB implementation allows the object to be saved.
reference: dexie/Dexie.js#647
Thanks for the bug report and the link to the Dexie discussion. I will have to try typeson some time and see how it performs.
This is fixed in realistic-structured-clone v2.0.0 and fake-indexeddb v2.0.4. Thanks again for the bug report!
Your bug report also led to a couple unrelated bug fixes in Typeson because I noticed some minor issues there when I started playing around with it.