From 606c4ffcd6e3bd051c596855f4ca2b562511bace Mon Sep 17 00:00:00 2001 From: uchida Date: Tue, 14 Apr 2026 09:50:12 +0900 Subject: [PATCH 1/2] fix: add null guard for awareness state in cursor plugin --- src/plugins/cursor-plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/cursor-plugin.js b/src/plugins/cursor-plugin.js index e2eb7bc..eba6753 100644 --- a/src/plugins/cursor-plugin.js +++ b/src/plugins/cursor-plugin.js @@ -95,7 +95,7 @@ export const createDecorations = ( return } - if (aw.cursor != null) { + if (aw && aw.cursor != null) { const user = aw.user || {} if (user.color == null) { user.color = '#ffa500' From 000bda234f4e7bd20bd77632a6cbb70bd1e1d0bf Mon Sep 17 00:00:00 2001 From: Yuichi Uchida Date: Sat, 9 May 2026 10:02:34 +0900 Subject: [PATCH 2/2] docs: clarify null guard and add changeset 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 --- .changeset/null-check-awareness-state.md | 5 +++++ src/plugins/cursor-plugin.js | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/null-check-awareness-state.md diff --git a/.changeset/null-check-awareness-state.md b/.changeset/null-check-awareness-state.md new file mode 100644 index 0000000..d212216 --- /dev/null +++ b/.changeset/null-check-awareness-state.md @@ -0,0 +1,5 @@ +--- +'@tiptap/y-tiptap': patch +--- + +Guard against null awareness state values in the cursor plugin so iterating over `awareness.getStates()` after a client disconnects no longer throws a TypeError when accessing `aw.cursor`. diff --git a/src/plugins/cursor-plugin.js b/src/plugins/cursor-plugin.js index eba6753..2aad076 100644 --- a/src/plugins/cursor-plugin.js +++ b/src/plugins/cursor-plugin.js @@ -95,6 +95,8 @@ export const createDecorations = ( return } + // `aw` can be null when a client disconnects, so we guard against it + // before reading `cursor` to avoid a TypeError. if (aw && aw.cursor != null) { const user = aw.user || {} if (user.color == null) {