From ec12e57ff5efc8ff06e27927fac4fe72ba6fa032 Mon Sep 17 00:00:00 2001 From: Szymon Kin <68154191+hoolek77@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:27:06 +0100 Subject: [PATCH] Fix updateHash function throwing errors when there are no headings visible at the screen (#125) --- src/scripts/updateHash.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/scripts/updateHash.ts b/src/scripts/updateHash.ts index fa44b77..412000e 100644 --- a/src/scripts/updateHash.ts +++ b/src/scripts/updateHash.ts @@ -18,6 +18,8 @@ const updateHash = (data: Data) => { }) .filter((section) => section.bottom > 0); + if (distancesToHeadingBottom.length === 0) return; + const currentSection = distancesToHeadingBottom.reduce((previous, current) => previous.bottom < current.bottom ? previous : current );