Skip to content

Run bounded beforeunload persistence tasks before pagehide teardown #880

Closed

Description

@wieslawsoltes

Problem

An unchanged VS Code OSS browser workbench can lose freshly stored workspace state during an immediate same-origin reload on WebScene. Its beforeunload handler calls storageService.flush(SHUTDOWN), which schedules the zero-delay IndexedDB flush. WebScene currently dispatches pagehide synchronously in the same native close/navigation call. VS Code handles pagehide by disposing the workbench and cancels the flush timer before any IndexedDB request starts.

Exact AppScene cd0a02e / WebScene a39280e4 Release evidence:

Proposed fix

Split the terminal lifecycle into bounded phases for top-level close/reload/navigation:

  1. dispatch cancelable beforeunload and honor veto/error synchronously;
  2. if it scheduled terminal-critical work, defer pagehide;
  3. drain only the already bounded lifecycle-descended zero-delay timer/IndexedDB lineage from Keep lifecycle-descended IndexedDB commits ahead of terminal navigation #878;
  4. dispatch pagehide exactly once, with the same bounded lineage rules;
  5. publish the terminal host request only after that work drains.

Do not admit intervals, delayed timers, unrelated pre-existing work, animation frames, or unbounded refilling. Clear phase state on veto, error, failed capacity reservation, successful handoff, realm reset, and teardown.

Acceptance

  • Add a focused native V8 regression modeling VS Code: beforeunload schedules a zero-delay persistence task and pagehide cancels outstanding timers; persistence completes before pagehide, then navigation is published.
  • Assert one beforeunload, one pagehide, one terminal request, preserved event order, and durable read in the replacement realm.
  • Retain Persist lifecycle IndexedDB work before navigation #879 budget/starvation exclusions.
  • Rebuild exact AppScene SDK/package and prove unchanged VS Code stores and reopens the real password input after reload.
  • Record focused wall time and repeated-cycle queue/live-count bounds.

Activity

  1. added
    bug
    vscode-oss/planned
    on Sep 20, 2026
  2. added
    vscode-oss/merged
    and removed
    vscode-oss/planned
    on Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugvscode-oss/merged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions