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

An empty line is added when the user opens or reloads the the document . #385

Open
Isini-Dananjana opened this issue Feb 23, 2023 Discussed in #384 · 5 comments
Open

Comments

@Isini-Dananjana
Copy link

Discussed in #384

Originally posted by Isini-Dananjana February 23, 2023
When using YJS with Plate, it adds a new line to the top of a shared document whenever a new user joins the collaboration session. I think this happens due to the following code found in yTextToSlateElement.

 const children =
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];

  return { ...yText.getAttributes(), children };

When multiple users are in the same document, this empty line that is added also gets synced, resulting in many empty lines.

Any idea how to resolve the issue?

@rcbevans
Copy link

I resolved this by making sure that the editor is not mounted until the yjs SyncStep2 has completed which means any existing clients have synced up their changes. If you mount too early, the data isn't yet synced, so the children is empty and the new line will be added.

@prabir-vora
Copy link

Not sure about Plate but I got it to work for the example in this repo the same way @rcbevans did. After configuring the HocusPocus provider, you can use the listener - provider.on('synced', ...callback) to set a flag to true that will then render your slate editor component. You need to move editor initialization code to a subcomponent which is only rendered after the flag is set tot true. This will make sure that the editor will already have the synced data state and not the empty data state when it is mounted and calls Normalize Node for the .

@juliankrispel
Copy link
Contributor

This is just the example implementation (which adds an empty paragraph automatically). If you remove that you'll be fine

@beeant0512
Copy link

@rcbevans can u share the core part code, or give a example

@dpnova
Copy link

dpnova commented Nov 27, 2024

FWIW I found that I couldn't get this to not happen because of the way plate plugins orchestrate things. The yjs stuff is set up inside the plate context, after you've done things like deal with initial value etc.

We added a normaliser to remove dupe empty lines at the top of the document.

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

No branches or pull requests

6 participants