Open ralphiee22 opened 1 year ago
Hi @ralphiee22,
This is a problem because undefined
is not valid JSON. You can try it out yourself: JSON.parse("{ val: undefined }")
throws an exception as well.
I'm not quite sure yet what the best course of action is. In any case, you should not set undefined
as a value. Hence, it would probably be best if Yjs would already throw an exception when you try to set undefined
.
Hence, it would probably be best if Yjs would already throw an exception when you try to set undefined.
I think this would be too much of a performance hit to verify there are no undefined properties being set, as we would need to iterate over the entire object (which is what we are doing as a workaround before encoding the document).
Formatting attributes in Yjs are JSON encoded and sent over the wire. Hence, Yjs cant accept undefined values as formatting attributes because they can't be JSON encoded. I can't change that.
In the future I will throw an error if someone tries to set undefined. I will leave the ticket open only to track that.
Checklist
Describe the bug Apply a delta (with undefined properties) to a ytext object. Encode the associated ydoc with
encodeStateAsUpdate
. Try applying the newly encoded state to another ydoc. JSON parse error is thrown.To Reproduce
Expected behavior Decoding to work properly with undefined properties.
Screenshots
Environment Information
Additional context I am not sure if YJS should be handling the undefined properties (or fail more gracefully), or we should never be passing undefined properties to the underlying shared types.
Huly®: YJS-317