Skip to content

Let two tabs of one project share the library — today neither hears the other's imports, and one tab's next write erases the other's stars and Recent entries #271

Open

Description

@bencode

Problem

The app routes each project to its own named window (ui-packages/web/src/features/projects/project-link.tsx:16-28), but nothing stops the same project from being open twice: a browser's Duplicate Tab, a bookmark to /p/<id>, or a pasted address all land a second tab on the same library. The deletion path already plans for this state — it shows "Waiting for other tabs that have X open to close." (ui-packages/web/src/shell/project-root.tsx:153-159; ui-packages/web/src/data/workspace-database.ts:142-150). Every other path ignores it:

  • The Files tree is listed once at mount (ui-packages/web/src/features/resources/use-file-library.ts:96-111) and only this tab's own writes reload it; no BroadcastChannel or storage-event listener exists anywhere in the source. A file imported, moved or removed in one tab never appears in the other's Files, Starred or Recent views until reload — and the assistant in the stale tab answers from the same behind list.
  • File navigation (view, Recent, starred) is read once at mount (ui-packages/web/src/features/resources/use-file-navigation.ts:20) and rewritten as one whole record on every change (use-file-navigation.ts:52; file-navigation.ts:58-67). Two tabs hold two copies, and whichever writes last drops the other's entries: a star set in tab B is erased from the record when tab A merely opens its next document, and after reload it is gone everywhere.
  • The saved workspace (open tabs, last active, positions) follows the same whole-value rule (ui-packages/web/src/features/workspace/use-workspace.ts:48,100-105,109-131; workspace-storage.ts:56-65). Tab B's position save — armed one second after a scroll pauses — writes the tab list it read at its mount, so a tab closed in A reopens at next launch and tabs A opened since B mounted vanish from the saved bar.

The reader's model is one library per project ("Included files and files added by the user should share one clear interaction model", ui-packages/web/PRODUCT.md); two windows on it disagree about what it holds, and the stale one silently destroys the reader's own marks with its next write.

Proposal

  • Pick one notification channel between tabs of a project — a BroadcastChannel named by the database, or the storage event that already fires only in the other tab — and post a change signal from the library's writes (import, move, remove, save, replace).
  • On that signal, re-list the library and re-read file navigation and the saved workspace, so both tabs show one library.
  • Stop letting a whole-value write drop entries its writer has never seen: stars, Recent entries and the saved tab list either merge on write, or move out of single whole-value records, so one tab can no longer erase another's.

Goal

After this, two tabs of one project behave as one library: a file added, moved or removed in either appears in both Files trees and in both assistants' reach, and no tab's write can erase a star, a Recent entry or an open-tab record another tab added — a star set in one tab still stands after the other opens a document.

Verification

if ! grep -rq "BroadcastChannel\|addEventListener('storage'" ui-packages/web/src; then echo 'no cross-tab channel yet'; exit 1; fi
pnpm --filter @gamma-reader/web test src/features/resources src/features/workspace
pnpm check

Refs

Activity

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

    @bencode
    OwnerAuthor

    Independent review — posted by the scheduled issue-reviewer loop, independent of the authoring session.

    Evidence audit: all citations confirmed on main (dbf9cb6).

    • Routing/awareness ✓ project-link.tsx:16-28 guards only plain left-clicks (duplicate tab / bookmark to /p/<id> bypasses the named window); project-root.tsx:155-158 carries the exact "Waiting for other tabs that have X open to close." string; workspace-database.ts:142-150 plans deletion around same-project tabs.
    • Read-once/write-whole ✓ use-file-library.ts:96-111 lists once at mount (useEffect → reload), only this tab's writes reload it; use-file-navigation.ts:20 reads at mount, :52 rewrites on every state change via file-navigation.ts:58-67 (whole-record JSON.stringify); use-workspace.ts:48 reads once, :100-105 writes whole on tab/active change, :109-131 defers position saves 1 s and ships the whole record from this tab's in-memory store (workspace-storage.ts:56-65). ✓ No BroadcastChannel or storage-event listener exists anywhere in src.
    • The erasure mechanism is real, not hypothetical: each tab's next write sends its mount-time snapshot, so a star set in tab B is dropped by tab A's next whole-write — and after reload it is gone in both. PRODUCT.md:31 ✓.

    Duplicate check: clean — #226 (assistant open-call contention) and #247 (positions on close) touch adjacent state; nothing covers cross-tab library sharing.

    Sensor: lint ✓. Verify was ungated as filed — repaired. The block was existing tests + pnpm check only, so verify passed on unfixed main — it could never fail, and a later beat would have closed this as implemented on a false signal (same defect as #269's block last beat). Per the anchor-repair rule I edited only the Verification block, prepending if ! grep -rq "BroadcastChannel\|addEventListener('storage'" ui-packages/web/src; then …; exit 1; fi — mechanism-neutral between the proposal's two channel options. Re-lint ✓; verify now fails on main (no cross-tab channel yet) → not implemented. Body edit logged: one line prepended to the Verification block, nothing else touched.

    Verdict: valid, stays open. Sharpening: bullet 3 is the substantive half — a channel alone does not stop the erasure, because the losing write happens in-memory before storage; the fix needs merge-on-write (or split records), and a unit test simulating two mount-time snapshots would anchor exactly the regression the title names.

  3. bencode commented on Oct 30, 2026

    @bencode
    OwnerAuthor

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

    Re-audit @ d05b6b6 — the review ran against dbf9cb6; the four plugins commits since touch conversation/plugins/shell surfaces, none of the cited files. Still valid; stays open.

    --

  4. bencode commented on Nov 5, 2026

    @bencode
    OwnerAuthor

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

    Re-audit @ d05b6b6 — no commits since the 10-30 review's base; still valid, stays open.

  5. bencode commented on Nov 7, 2026

    @bencode
    OwnerAuthor

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

    Re-audit at d05b6b6 (fourth pass; HEAD unchanged since 2026-10-28) — valid, stays open; no edits.

    Verdict unchanged; the standing sharpening remains the substantive one: a channel alone does not stop the erasure (the losing write is in-memory before storage) — the fix needs merge-on-write or split records, and a two-snapshot unit test would anchor the star-erasure regression the title names.

  6. bencode commented on Nov 11, 2026

    @bencode
    OwnerAuthor

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

    Re-audit (fifth pass) @ d05b6b6 — HEAD unchanged since 2026-10-28; valid, stays open.

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