diff --git a/src/systems/features/chapterCheckpoint.js b/src/systems/features/chapterCheckpoint.js index 0f8d24c..5ac2c41 100644 --- a/src/systems/features/chapterCheckpoint.js +++ b/src/systems/features/chapterCheckpoint.js @@ -14,6 +14,7 @@ let currentlyHiddenRange = null; // Debounce restore to prevent loops let isRestoring = false; let restoreTimeout = null; +let pendingResolve = null; /** * Gets the current chapter checkpoint message ID for the active chat @@ -129,13 +130,19 @@ export async function restoreCheckpointOnLoad() { return; } - // Clear any pending timeout + // Clear any pending timeout and resolve the pending promise if (restoreTimeout) { clearTimeout(restoreTimeout); + restoreTimeout = null; + } + if (pendingResolve) { + pendingResolve(); + pendingResolve = null; } // Debounce: wait 100ms before actually restoring return new Promise((resolve) => { + pendingResolve = resolve; restoreTimeout = setTimeout(async () => { isRestoring = true; try { @@ -174,6 +181,7 @@ export async function restoreCheckpointOnLoad() { } } finally { isRestoring = false; + pendingResolve = null; resolve(); } }, 100);