tiptap icon indicating copy to clipboard operation
tiptap copied to clipboard

[Bug]: attrs json object in heading does not have Object prototype

Open emil14 opened this issue 1 year ago • 6 comments

Which packages did you experience the bug in?

tiptap-core

What Tiptap version are you using?

2.1.13

What’s the bug you are facing?

Looks like attrs object (e.g. {level: 1} in my case) does not have Object as it's prototype and as a result calling attrs.hasOwnProperty will throw exception.

Can't you just do something like Object.prototype.hasOwnProperty(attrs, 'level') you may ask? No, I'm not the one who do it. I use a library rxdb and

I created an issue in their repo but I think this should be fixed on both sides. There could be many more such cases.

This issue is critical for my app so if they won't fix it it would be awesome if you will. Please help. Thank u!

https://github.com/pubkey/rxdb/issues/5382

What browser are you using?

Chrome

Code example

No response

What did you expect to happen?

I expect call to hasOwnProperty do not throw

Anything to add? (optional)

No response

Did you update your dependencies?

  • [X] Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • [ ] Yes, I’m a sponsor. 💖

emil14 avatar Dec 14 '23 16:12 emil14

Also hit attrs not having a prototype, it breaks serialization of docs in my project.

bbss avatar Apr 15 '24 10:04 bbss

This is causing issues with next.js/react server actions as well. Next.js uses getPrototypeOf when resolving a JSON payload and missing Object prototype is causing exceptions.

sonnyt avatar Jul 14 '24 01:07 sonnyt

Are you saying that this.editor.getJSON() does not actually return JSON? i.e. it is creating objects with a null prototype?

How are you accessing this values?

nperez0111 avatar Jul 17 '24 08:07 nperez0111

Are you saying that this.editor.getJSON() does not actually return JSON? i.e. it is creating objects with a null prototype?

How are you accessing this values?

I am using getJSON(). Yes, it seems like attrs object for headings is created with a null prototype.

sonnyt avatar Jul 18 '24 00:07 sonnyt

I am using getJSON(). Yes, it seems like attrs object for headings is created with a null prototype.

Ah okay, well this is because you are calling prosemirror's API for this. This is not an issue with tiptap per se but the underlying library. Honestly I would just JSON.parse(JSON.stringify(attrs.getJSON())) which should give you a straight json object

nperez0111 avatar Jul 18 '24 06:07 nperez0111