Skip to content

Cap what open tabs hold in memory — every visited tab stays mounted today, and each open PDF keeps its loaded document until the tab closes #175

Open

Description

@bencode

Problem

Every tab a reader has ever looked at stays fully mounted. DocumentTabs maps over all open tabs and renders a pane for each (ui-packages/web/src/features/reader/document-tabs.tsx:283-305); once a tab has been active, its pane is forceMounted inside <Activity mode="hidden"> and never unmounted (ui-packages/web/src/features/reader/document-pane.tsx:17-31). For PDFs that means the loaded pdf.js document, its bytes, and the blob ObjectURL all stay alive until the tab is closed — pdfSources revokes a URL only when its id leaves workspace.tabs (document-tabs.tsx:164-173). Nothing caps how many tabs stay open (workspace-store.ts:95-101 is an unbounded string[]), and the product's own verb is comparing files (ui-packages/web/PRODUCT.md:19). A reader comparing a shelf of reports in a browser — on iOS Safari, where a few hundred MB gets the page killed, the platform #167 already worries about — pays for every document they opened, not the ones they are reading.

Proposal

  • Keep only the most recently used hidden panes mounted (a small fixed number, e.g. 3); unmount the rest's content while keeping their tab, title and place in the tab bar.
  • Restore an evicted pane on revisit from the position the workspace already records — defaultPosition={workspace.store.getState().positions[id]} (document-tabs.tsx:296-300) is read at mount and already carries the scroll state.
  • Release an evicted PDF's ObjectURL by reusing the existing pdfSources cleanup instead of waiting for tab close.
  • Never evict a pane whose lab is running: the lab runner lives inside the mounted reader (features/assistant/lab-tools.ts:21-22), so evicting it would kill a run.

Goal

After this, memory grows with the documents a reader is actually reading, not with how many they opened today: opening and revisiting many documents keeps a bounded number of loaded readers alive, and closing a tab is no longer the only thing that frees its document.

Verification

grep -rwiE "evict|unload|unmount|suspend|keepMounted|mountedPanes" ui-packages/web/src/features/reader ui-packages/web/src/features/workspace --include='*.ts' --include='*.tsx' --exclude='*test*'
pnpm --filter @gamma-reader/web test --silent
pnpm check

Refs

  • ui-packages/web/src/features/reader/document-tabs.tsx:283-305 — every open tab renders a pane
  • ui-packages/web/src/features/reader/document-pane.tsx:17-31 — visited panes forceMount inside Activity and never unmount
  • ui-packages/web/src/features/reader/document-tabs.tsx:164-173 — a PDF's blob URL is freed only when its tab closes
  • ui-packages/web/src/features/workspace/workspace-store.ts:95-101 — open tabs are unbounded
  • ui-packages/web/src/features/reader/document-tabs.tsx:296-300 — mount-time position restore, already enough to rehydrate an evicted pane
  • ui-packages/web/src/features/assistant/lab-tools.ts:21-22 — the lab runner lives in the mounted reader, so it must be exempt
  • ui-packages/web/PRODUCT.md:19 — "importing, previewing, comparing, and discussing files feel immediate"
  • Remember where the reader stopped — reopen documents at their page or scroll position #40 — the position memory this builds on
  • Keep the Files panel fluent at the 5000-file import cap — every row renders today, unwindowed #166 — sibling scale issue (Files panel renders every row); this one is the document panes

Activity

  1. added
    enhancement
    source:scheduled
    on Oct 22, 2026
  2. bencode commented on Oct 22, 2026

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop (a session separate from the one that files these issues), under the maintainer's standing instruction to evaluate, sharpen, or retire source:scheduled proposals. Audited against main@ebb0ee0.

    Evidence audit: all load-bearing citations confirmed; one one-line drift.

    Sensor + Verification block repaired (logged here per policy): lint ✓, but verify falsely passed on unmodified main — grep -rqiE "evict|unload|suspend" case-insensitively matches beforeunload in workspace-context.tsx:101-103 (the very guard #167 is about). Same disease as #157/#158's blocks. Edited only the Verification block:

    -grep -rqiE "evict|unload|suspend" ui-packages/web/src/features/reader ui-packages/web/src/features/workspace
    +grep -rwiE "evict|unload|unmount|suspend|keepMounted|mountedPanes" ui-packages/web/src/features/reader ui-packages/web/src/features/workspace --include='*.ts' --include='*.tsx' --exclude='*test*'

    Word boundaries kill the beforeunload false match; the broadened list covers the natural implementation names. Re-linted ✓; verify now ✗ on main ✓ (not implemented).

    Verdict: valid, keep open. Two sharpenings for implementation: (1) the lab exemption has a free mechanism — registerLab's unregister-on-unmount means the eviction policy can simply ask the context which runners exist; the test should pin that a running lab's pane is never evicted. (2) Evicting a PDF releases its ObjectURL, so a revisit must re-read bytes from the store — the position restore is already mount-time, but the test should assert a revisit after eviction restores position, not just the document.

  3. bencode commented on Oct 24, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Prior review (above) audited main@ebb0ee0; this beat re-checks it against main@90b046f, the stalest-reviewed issue relative to commits landed since.

    Drift since ebb0ee0: the drag-tabs work (614abd0/101c45f) touched the tab bar (features/reader/document-tabs.tsx, document-tab-bar/) — not this issue's subject, pane lifecycle. Of the cited anchors, only one moved: workspace-store.ts gained moveTab (+7 lines, :55-61), shifting the setTabs citation from :95-101 to :103-108; setTabs still has no cap. features/workspace/document-tabs.tsx and document-pane.tsx are byte-identical — the load-bearing citations (per-id panes under forceMount, ObjectURL revoke only on tab close, mount-time position read) all stand.

    Sensor: lint ✓; verify ✗ on main ✓ — the anchor repaired in the prior review is still red (no evict/unload/unmount/suspend/keepMounted/mountedPanes in reader or workspace, tests excluded).

    Verdict: unchanged — valid, keep open. The original sharpenings stand, and reordering strengthens the second one: with tabs now draggable, a revisit after eviction must restore the pane's position and land it in the current (possibly re-dragged) order — the order comes from workspace.tabs, but the test should pin both together.

  4. bencode commented on Oct 27, 2026

    @bencode
    OwnerAuthor

    Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Prior review audited main@90b046f; this beat re-checks the stalest-reviewed issue against main@0439ecf (11 commits since).

    Drift since 90b046f: none. The sheet/reader fixes since then (chart sheet, cell bar, open-at-page, pdf worker order, notices) never touch this issue's anchors — git diff --stat 90b046f..HEAD over workspace-store.ts, workspace-context.tsx, document-tabs.tsx, document-pane.tsx, lab-tools.ts, PRODUCT.md is empty. setTabs still at workspace-store.ts:103-108 with no cap; panes still render per-id under unconditional forceMount.

    Sensor: lint ✓; verify ✗ on main ✓ (no evict/unload/unmount/suspend/keepMounted/mountedPanes in reader or workspace).

    Verdict: unchanged — valid, keep open. Both sharpenings from the prior review stand (running-lab pane never evicted via registerLab; revisit after eviction restores position and current tab order).

  5. bencode commented on Nov 2, 2026

    @bencode
    OwnerAuthor

    Posted by the scheduled issue-reviewer loop, independent of the authoring session.

    Re-audit at d05b6b6 — the stalest remaining review (8 commits since the last @ 0439ecf, the whole plugins series; git diff --stat 0439ecf..HEAD over all six cited files is empty). Valid, stays open; no edits.

  6. bencode commented on Nov 13, 2026

    @bencode
    OwnerAuthor

    Posted by the scheduled issue-reviewer loop, independent of the authoring session.

    Re-audit at d05b6b6 — second-stalest review this beat (12 days). HEAD still unchanged since 2026-10-28; valid, stays open; no edits.

    Verdict unchanged: valid, keep open. Both sharpenings from the earlier reviews stand (never evict a running lab's pane via registerLab; revisit after eviction restores position and current tab order).

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

    enhancementsource:scheduled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions