Skip to content

fix: flush pending debounced localStorage saves on pagehide in standalone dev harness - #1425

Closed
siefkenj with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-review-comments
Closed

fix: flush pending debounced localStorage saves on pagehide in standalone dev harness#1425
siefkenj with Copilot wants to merge 8 commits into
mainfrom
copilot/fix-review-comments

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Addresses review comments from #pullrequestreview-4656536637 on PR #1423 (autosave dev sources in localStorage).

Changes

packages/standalone/src/test-main.tsx

  • Adds a pendingSources: Map<string, string> to track writes scheduled but not yet persisted
  • Adds a pagehide listener that cancels pending timers and flushes all pending sources synchronously — mirrors the identical pattern already used in doenetml-iframe/src/test-main.tsx
  • saveSource() now tracks/clears entries in pendingSources alongside saveTimers
window.addEventListener("pagehide", () => {
    for (const [key, source] of pendingSources) {
        const timer = saveTimers.get(key);
        if (timer !== undefined) {
            window.clearTimeout(timer);
            saveTimers.delete(key);
        }
        try {
            localStorage.setItem(key, source);
            pendingSources.delete(key);
        } catch { /* ignore */ }
    }
    pendingSources.clear();
});

packages/doenetml-iframe/src/test-main.tsx

  • Changes saveTimer type from number | nullReturnType<typeof window.setTimeout> | null for consistency with the standalone implementation and correctness when Node types are in scope

siefkenj and others added 4 commits July 7, 2026 19:21
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code based on review comments fix: flush pending debounced localStorage saves on pagehide in standalone dev harness Jul 8, 2026
Copilot AI requested a review from siefkenj July 8, 2026 17:40
@siefkenj siefkenj closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants