From 61f466afc099a2c2f0777e2f3aaebaf0e8cc028b Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 15 Oct 2021 10:47:45 +0100 Subject: [PATCH] Ignore invalid synctex highlights (#5476) GitOrigin-RevId: 9123a09502f17c1251995b2e7133b345db885107 --- .../pdf-preview/components/pdf-js-viewer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.js b/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.js index 75998c2f62..e81860486b 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.js +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-js-viewer.js @@ -146,12 +146,19 @@ function PdfJsViewer({ url }) { // when highlights are created, build the highlight elements useEffect(() => { if (pdfJsWrapper && highlights?.length) { - const elements = highlights.map(highlight => - buildHighlightElement(highlight, pdfJsWrapper.viewer) - ) + const elements = [] + + for (const highlight of highlights) { + try { + const element = buildHighlightElement(highlight, pdfJsWrapper.viewer) + elements.push(element) + } catch (error) { + // ignore invalid highlights + } + } // scroll to the first highlighted element - elements[0].scrollIntoView({ + elements[0]?.scrollIntoView({ block: 'start', inline: 'nearest', behavior: 'smooth',