Skip to content

fix: add null guard for awareness state in createDecorations#27

Merged
arnaugomez merged 2 commits into
ueberdosis:mainfrom
yuichi0301:fix/null-check-awareness-state
May 9, 2026
Merged

fix: add null guard for awareness state in createDecorations#27
arnaugomez merged 2 commits into
ueberdosis:mainfrom
yuichi0301:fix/null-check-awareness-state

Conversation

@yuichi0301
Copy link
Copy Markdown
Contributor

Problem

In createDecorations, awareness.getStates().forEach() iterates over
awareness states, but the state value (aw) can be null or undefined
(e.g. when a client disconnects). Accessing aw.cursor without a null
check causes a TypeError.

Solution

Added a null guard (aw &&) before accessing aw.cursor on line 98 of
src/plugins/cursor-plugin.js.

@yuichi0301
Copy link
Copy Markdown
Contributor Author

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): awareness.getStates() can contain transient null/undefined entries when clients disconnect, which causes a TypeError on aw.cursor. The fix is a one-line aw && guard.

Happy to add a test or iterate on the approach. Thanks!

Copy link
Copy Markdown
Contributor

@arnaugomez arnaugomez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@yuichi0301
Copy link
Copy Markdown
Contributor Author

@arnaugomez

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
Added an inline comment explaining that aw can be null when a client disconnects, which is why the guard is needed
Let me know if you'd like any tweaks to the wording.

@arnaugomez arnaugomez merged commit 4e97c2f into ueberdosis:main May 9, 2026
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.

2 participants