From 34d70afadf8859fa5ed58928a028141f4f4d41fb Mon Sep 17 00:00:00 2001 From: Rich Evans Date: Thu, 23 Feb 2023 12:44:20 -0800 Subject: [PATCH] fix: deleteText currPos left and right both null Handle the case where both `currPos.left` and `currPos.right` are null in `YText::deleteText` to prevent error `Cannot read properties of null (reading 'parent')` . Fixes https://github.com/yjs/yjs/issues/504. --- src/types/YText.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/types/YText.js b/src/types/YText.js index d1cdf781..71d6a030 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -498,8 +498,8 @@ const deleteText = (transaction, currPos, length) => { if (start) { cleanupFormattingGap(transaction, start, currPos.right, startAttrs, currPos.currentAttributes) } - const parent = /** @type {AbstractType} */ (/** @type {Item} */ (currPos.left || currPos.right).parent) - if (parent._searchMarker) { + const parent = /** @type {AbstractType} */ (/** @type {Item} */ (currPos.left || currPos.right)?.parent) + if (parent?._searchMarker) { updateMarkerChanges(parent._searchMarker, currPos.index, -startLength + length) } return currPos