Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow falsy attribute values #619

Merged
merged 1 commit into from Mar 1, 2024

Conversation

jul13579
Copy link
Contributor

@jul13579 jul13579 commented Mar 1, 2024

Hi Yjs-folks!

First of all thanks for this awesome piece of software ❤️ I'm currently working on the integration of a slate-based editor into my app, using slate-yjs to allow collaborative editing. During testing of the editor I came across an issue, where using falsy attribute values lead to problems within slate-yjs. I found the reason of the problems within slate-yjs however to be caused by this LOC within yjs.

To better understand this problem, please picture the following scenario:
I got a document with a YXmlText that looks like the following after calling .toJSON().

<fontface><fontsize>Some Text</fontsize></fontface>

The YXmlText therefore has the attributes fontface and fontsize, however in this case both are set to an empty string (''), resulting in the above representation. When I insert any character within that text, passing the same attributes ({fontface: '', fontsize: ''}), YText#insertAttributes will drop the falsy attributes, resulting in different attributes for the inserted character, despite me passing in the same attributes as the surrounding text. This then leads to slate-yjs having trouble mapping a slate document node to a YXmlText node, because for one document node there suddenly are multpile YXmlText nodes with differing attributes.

This MR fixes this issue, by replacing the logical or operation in the above linked LOC with the nullish coalescing operator. However, I'm unsure if your implementation using the logical or operation is by design. Maybe this operation was chosen to minimize YDoc storage consumption?

@dmonad
Copy link
Member

dmonad commented Mar 1, 2024

This is definitely a bug! Thank you for the PR!

I'll make a release shortly.

@dmonad dmonad merged commit 83db6c8 into yjs:main Mar 1, 2024
2 checks passed
dmonad added a commit that referenced this pull request Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants