Skip to content

Commit 433dd40

Browse files
committed
Update: fix for render static
1 parent 5245304 commit 433dd40

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

Dist/WebflowOnly/RenderStatic.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,27 @@ class RenderStatic {
2525

2626
let insertIndex = this.gap;
2727
const totalChildren = childrenArray.length;
28-
const totalInsertions = Math.round(totalChildren / this.gap);
2928
let cloneIndex = 0;
3029

31-
for (let i = 0; i <= totalChildren + totalInsertions; i++) {
32-
if (i === insertIndex) {
33-
this.insertChildAtIndex(this.container, this.cloneables[cloneIndex], insertIndex);
34-
cloneIndex = (cloneIndex < this.cloneables.length - 1) ? cloneIndex + 1 : 0;
35-
insertIndex = i + this.gap + 1;
36-
}
30+
const maxInsertions = Math.floor((totalChildren - 1) / this.gap);
31+
32+
for (let i = 0; i < maxInsertions; i++) {
33+
const currentIndex = i * (this.gap + 1) + this.gap;
34+
35+
if (currentIndex >= totalChildren) break;
36+
37+
this.insertChildAtIndex(this.container, this.cloneables[cloneIndex], currentIndex);
38+
cloneIndex = (cloneIndex < this.cloneables.length - 1) ? cloneIndex + 1 : 0;
3739
}
3840

3941
this.observeContainer();
4042
}
4143

4244
insertChildAtIndex(parent, child, index = 0) {
4345
if (!child) return;
44-
if (parent.children.length === index) return;
46+
47+
if (index >= parent.children.length) return;
48+
4549
let childClone = child.cloneNode(true);
4650
if (parent) {
4751
parent.insertBefore(childClone, parent.children[index]);
@@ -77,5 +81,5 @@ const initializeRenderStatic = () => {
7781
if (/complete|interactive|loaded/.test(document.readyState)) {
7882
initializeRenderStatic();
7983
} else {
80-
window.addEventListener('DOMContentLoaded',initializeRenderStatic )
81-
}
84+
window.addEventListener('DOMContentLoaded', initializeRenderStatic);
85+
}

0 commit comments

Comments
 (0)