fallback index in case element not found
This commit is contained in:
parent
a502e49f78
commit
db72eeba71
15
src/frame.ts
15
src/frame.ts
@ -470,10 +470,13 @@ export const addElementsToFrame = (
|
|||||||
|
|
||||||
let nextElements = allElements.slice();
|
let nextElements = allElements.slice();
|
||||||
// Optimisation since findIndex on "newElements" is slow
|
// Optimisation since findIndex on "newElements" is slow
|
||||||
const nextElementsIndex = nextElements.reduce((acc, element, index) => {
|
const nextElementsIndex = nextElements.reduce(
|
||||||
acc[element.id] = index;
|
(acc: Record<string, number | undefined>, element, index) => {
|
||||||
return acc;
|
acc[element.id] = index;
|
||||||
}, {} as Record<string, number>);
|
return acc;
|
||||||
|
},
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
|
||||||
const frameBoundary = findIndex(nextElements, (e) => e.frameId === frame.id);
|
const frameBoundary = findIndex(nextElements, (e) => e.frameId === frame.id);
|
||||||
for (const element of omitGroupsContainingFrames(
|
for (const element of omitGroupsContainingFrames(
|
||||||
@ -489,8 +492,8 @@ export const addElementsToFrame = (
|
|||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
||||||
const frameIndex = nextElementsIndex[frame.id];
|
const frameIndex = nextElementsIndex[frame.id] ?? -1;
|
||||||
const elementIndex = nextElementsIndex[element.id];
|
const elementIndex = nextElementsIndex[element.id] ?? -1;
|
||||||
|
|
||||||
if (elementIndex < frameBoundary) {
|
if (elementIndex < frameBoundary) {
|
||||||
nextElements = [
|
nextElements = [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user