diff --git a/src/manager/documents.js b/src/manager/documents.js index 90dcb462d..6506fa299 100644 --- a/src/manager/documents.js +++ b/src/manager/documents.js @@ -32,6 +32,9 @@ const PROCESSING_CHANGE_TIMEOUT = 500; function mapReduce(l, id, fn) { const results = {}; + if (!l || l.length === 0) { + return results; + } for (let i = 0; i < l.length; i++) { const x = l[i]; results[x[id]] = fn(x); @@ -98,7 +101,7 @@ export const documents = new Svue({ }, pendingExisting(docsById, pending) { if (!pending) return []; - return pending.filter((x) => { + return pending?.filter((x) => { const id = x.doc_id; return docsById[id] != null; }); diff --git a/src/util/coalesceHighlights.js b/src/util/coalesceHighlights.js index b59b17802..6d03921df 100644 --- a/src/util/coalesceHighlights.js +++ b/src/util/coalesceHighlights.js @@ -107,7 +107,8 @@ export function coalesceSelectableHighlights(words, highlights) { while (textBlock.length > 0) { // Go through each text object const text = - leftoverText + words[seekI].text.toLowerCase().replace(/\s/g, ""); + leftoverText + + words[seekI]?.text?.toLowerCase().replace(/\s/g, "") ?? ""; if (!textBlock.startsWith(text) && !text.startsWith(textBlock)) { // Not a match: abort matched = false;