From 87f55eabf6a3056f6c8e49e67e3028f6bf749824 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 19 May 2023 10:54:43 +0800 Subject: [PATCH] fix: sentry report on node is null --- packages/api/src/utils/highlightGenerator.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/api/src/utils/highlightGenerator.ts b/packages/api/src/utils/highlightGenerator.ts index 0146e4251..58bcf325d 100644 --- a/packages/api/src/utils/highlightGenerator.ts +++ b/packages/api/src/utils/highlightGenerator.ts @@ -66,6 +66,8 @@ function getTextNodesBetween(rootNode: Node, startNode: Node, endNode: Node) { } function getTextNodes(node: Node) { + if (!node) return + if (node == startNode) { pastStartNode = true } @@ -384,7 +386,7 @@ export function makeHighlightNodeAttributes( patch: string, document: Document ) { - const rootNode = document.documentElement + const rootNode = document.getRootNode() const allArticleNodes = getTextNodesBetween(rootNode, rootNode, rootNode) const { highlightTextStart, highlightTextEnd, textNodes, textNodeIndex } =