From c323d78b805574d5673f0d42fd71e09fa5ce9922 Mon Sep 17 00:00:00 2001 From: komalg1 Date: Wed, 29 May 2024 10:38:05 +0100 Subject: [PATCH] fix: Frontend crash due to invalid citations (#1002) --- code/frontend/src/components/Answer/AnswerParser.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/frontend/src/components/Answer/AnswerParser.tsx b/code/frontend/src/components/Answer/AnswerParser.tsx index 0717ec3e7..8d248673d 100644 --- a/code/frontend/src/components/Answer/AnswerParser.tsx +++ b/code/frontend/src/components/Answer/AnswerParser.tsx @@ -19,7 +19,7 @@ export function parseAnswer(answer: AskResponse): ParsedAnswer { // Replacing the links/citations with number let citationIndex = link.slice(lengthDocN, link.length - 1); let citation = cloneDeep(answer.citations[Number(citationIndex) - 1]) as Citation; - if (!filteredCitations.find((c) => c.id === citationIndex)) { + if (!filteredCitations.find((c) => c.id === citationIndex) && citation !== undefined) { answerText = answerText.replaceAll(link, ` ^${++citationReindex}^ `); citation.id = citationIndex; // original doc index to de-dupe citation.reindex_id = citationReindex.toString(); // reindex from 1 for display