Skip to content

Flush pending standalone dev-source autosaves on pagehide - #1426

Closed
siefkenj with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-code-for-review-comment
Closed

Flush pending standalone dev-source autosaves on pagehide#1426
siefkenj with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-code-for-review-comment

Conversation

Copilot AI commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

The standalone dev editor persisted source changes with a debounce, which could drop the most recent edits if the page was reloaded or closed before the timer fired. This updates the dev harness to flush pending autosave state during pagehide.

  • Autosave flush on unload

    • Track the latest unsaved editor source per standalone editor instance.
    • Flush any pending debounced localStorage write when the page is being hidden.
  • Keep existing debounce behavior

    • Preserve the current debounced save path during normal editing.
    • Clear pending state after either the scheduled save or the pagehide flush runs.
  • Scope

    • Change is limited to the standalone dev harness in packages/standalone/src/test-main.tsx.
window.addEventListener("pagehide", () => {
  for (const [key, source] of pendingSources) {
    const pending = saveTimers.get(key);
    if (pending !== undefined) {
      window.clearTimeout(pending);
      saveTimers.delete(key);
    }
    localStorage.setItem(key, source);
  }
  pendingSources.clear();
});

siefkenj and others added 5 commits July 8, 2026 17:42
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>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code as per review comment Flush pending standalone dev-source autosaves on pagehide Jul 8, 2026
Copilot AI requested a review from siefkenj July 8, 2026 17:44
@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