Yjs: Editor adds leading/trailing empty paragraph in addition to what server returned from onLoadDocument #4387
-
DescriptionWhen loading the editor (after a refresh for example) it will add an empty leading or trailing paragraph itself. Attempts to normalize this away only led to the document moving the last node to the top. Oh, and the editor does not seem to render at all with Reproduction URLhttps://github.com/eriksson-daniel/yjs-init Reproduction steps1. Let content be loaded from onLoadDocument in HocusPocus
2. Refresh
3. Observe that a trailing or leading empty paragraph is added Plate version49.0.3 Slate React version0.117.1 ScreenshotsLogsBrowsersChrome, Firefox |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi @eriksson-daniel! I'm Dosu and I’m helping the plate team. The extra leading or trailing empty paragraph comes from Plate's normalization logic, which always ensures at least one top-level block node is present. When loading content from Yjs (like onLoadDocument), if the content doesn't meet Plate's minimum block requirements, it may add an empty paragraph—sometimes at the start or end—especially if the document appears empty or is missing a block node. This is a side effect of how Plate, Slate, and Yjs interact during initialization and normalization. For the rendering issue with If you want to avoid the extra paragraph, ensure your loaded document always contains at least one valid block node (like a paragraph) before passing it to Plate, or adjust your normalization logic to better fit your use case. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
The extra leading or trailing empty paragraph is likely caused by normalization logic that ensures the document always has a valid structure—often inserting a paragraph if the document is empty or doesn't end with a block. When using Yjs, the timing between loading the remote document and Plate's normalization can cause redundant empty paragraphs to appear, especially if the editor initializes before the Yjs content is fully loaded. For the rendering issue with In summary: ensure you initialize the editor only after your Yjs content is loaded, and use the new APIs to control normalization and rendering. This should help prevent both the extra paragraph issue and the rendering problem with To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
@dosu I'm confused.
|
Beta Was this translation helpful? Give feedback.
It looks like you need to wait for onConnect/onSync before calling
init