From db72eeba71266ef0e584cf16c4cccd8b600ff1d8 Mon Sep 17 00:00:00 2001 From: dwelle Date: Wed, 9 Aug 2023 00:08:19 +0200 Subject: [PATCH] fallback index in case element not found --- src/frame.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/frame.ts b/src/frame.ts index 543f237d7..7f0f42d7a 100644 --- a/src/frame.ts +++ b/src/frame.ts @@ -470,10 +470,13 @@ export const addElementsToFrame = ( let nextElements = allElements.slice(); // Optimisation since findIndex on "newElements" is slow - const nextElementsIndex = nextElements.reduce((acc, element, index) => { - acc[element.id] = index; - return acc; - }, {} as Record); + const nextElementsIndex = nextElements.reduce( + (acc: Record, element, index) => { + acc[element.id] = index; + return acc; + }, + {}, + ); const frameBoundary = findIndex(nextElements, (e) => e.frameId === frame.id); for (const element of omitGroupsContainingFrames( @@ -489,8 +492,8 @@ export const addElementsToFrame = ( false, ); - const frameIndex = nextElementsIndex[frame.id]; - const elementIndex = nextElementsIndex[element.id]; + const frameIndex = nextElementsIndex[frame.id] ?? -1; + const elementIndex = nextElementsIndex[element.id] ?? -1; if (elementIndex < frameBoundary) { nextElements = [