Skip to content

Commit a5c16d7

Browse files
fix: pagination logic for version history - preserve versions array and add debug logging
1 parent df275b1 commit a5c16d7

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

index.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,10 +3120,16 @@ <h2 class="section-title">
31203120
__visibleVersionCount = options.visibleCount;
31213121
}
31223122

3123-
// Clamp
3123+
// Clamp - ensure we have data to work with
31243124
if (!__visibleVersionCount || __visibleVersionCount < 1) {
31253125
__visibleVersionCount = Math.min(__LOAD_INCREMENT, __allVersions.length || 0);
31263126
}
3127+
3128+
// Safety check
3129+
if (!__allVersions || __allVersions.length === 0) {
3130+
console.warn("No versions available for rendering");
3131+
return;
3132+
}
31273133

31283134
const versionList = document.getElementById("version-list");
31293135

@@ -3205,18 +3211,23 @@ <h2 class="section-title">
32053211
if (existingMore) existingMore.remove();
32063212

32073213
if (__visibleVersionCount < (__allVersions || []).length) {
3214+
const remainingCount = (__allVersions || []).length - __visibleVersionCount;
3215+
const nextBatchSize = Math.min(__LOAD_INCREMENT, remainingCount);
3216+
32083217
const moreBtn = document.createElement("button");
32093218
moreBtn.id = "load-more-versions";
32103219
moreBtn.className = "expand-toggle";
32113220
moreBtn.style.marginTop = "0.75rem";
3212-
moreBtn.innerHTML = '<span>Show older versions</span><span class="expand-icon" style="transform: rotate(45deg); margin-left: 0.25rem"></span>';
3221+
moreBtn.innerHTML = `<span>Show ${nextBatchSize} older versions</span><span class="expand-icon" style="transform: rotate(45deg); margin-left: 0.25rem"></span>`;
32133222
moreBtn.addEventListener("click", (e) => {
32143223
e.preventDefault();
3224+
console.log(`Loading more versions. Current: ${__visibleVersionCount}, Total: ${__allVersions.length}`);
32153225
__visibleVersionCount = Math.min(
32163226
__visibleVersionCount + __LOAD_INCREMENT,
32173227
(__allVersions || []).length,
32183228
);
3219-
renderVersionHistory(undefined, { visibleCount: __visibleVersionCount });
3229+
console.log(`New visible count: ${__visibleVersionCount}`);
3230+
renderVersionHistory(null, { visibleCount: __visibleVersionCount });
32203231
});
32213232
versionList.parentElement.appendChild(moreBtn);
32223233
}

0 commit comments

Comments
 (0)