fix: add null guard for awareness state in createDecorations#27
Conversation
|
Friendly ping 👋 @arnaugomez — would appreciate your eyes on this when you have a moment, since you recently worked on the cursor plugin in #8. This is the y-tiptap counterpart of the same null-guard issue I'm also fixing in tiptap (ueberdosis/tiptap#7740): Happy to add a test or iterate on the approach. Thanks! |
arnaugomez
left a comment
There was a problem hiding this comment.
Hi! Thanks for your contribution.
Add a changeset and we'll merge. See contributing guide.
Besides, you can add a comment explaining why the null check, and that aw can be null when the client disconnects.
Add an inline comment explaining that awareness states can be null after a client disconnects, and add a patch changeset entry as requested in PR review. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Thanks for the review! I've pushed a follow-up commit (000bda2) addressing both points: Added a .changeset/null-check-awareness-state.md patch entry |
Problem
In
createDecorations,awareness.getStates().forEach()iterates overawareness states, but the state value (
aw) can benullorundefined(e.g. when a client disconnects). Accessing
aw.cursorwithout a nullcheck causes a
TypeError.Solution
Added a null guard (
aw &&) before accessingaw.cursoron line 98 ofsrc/plugins/cursor-plugin.js.