Bug: Listeners fire on initialization with CollaborationPlugin
- Dominant language
- TypeScript
- Stars
- 23.9k
- Forks
- 2.2k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 61
Description
When the CollaborationPlugin handles changing documents by receiving a different id, the listeners fire.
Of course, listeners should not fire on document initialization/change.
I've noticed that this doesn't happen with the OnChangePlugin, because it checks that the previous editorState is not null, apparently to avoid this situation:
```javascript
return editor.registerUpdateListener(
({ editorState, dirtyElements, dirtyLeaves, prevEditorState, tags }) => {
if (prevEditorState.isEmpty()) return;
// ...
}
);
```
Ideally, this should be the default behavior. But the problem is that even if you wanted to, you couldn't imitate this trick with the other listeners, since updateListener is the only one that receives `prevEditorState` as callback.
Lexical version: 0.9.1
## Steps To Reproduce
1. `npm run dev`
2. In another terminal, `npm run collab-server`
3. In the browser, click on the buttons to change the document, and you will see that `content changed` appears in the console.
Link to code example: https://github.com/EgonBolton/collab
## The current behavior
The listeners are fired, as seen in the console.
## The expected behavior
I think the listeners should not fire in this case.
Contributor guide
Research direction
Start by running `npm run dev` and `npm run collab-server`, then use the linked collaboration example to reproduce document changes. Trace the CollaborationPlugin listener registration and compare it with the OnChangePlugin behavior shown in the issue. Done means changing the document by id does not log `content changed` during initialization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100