From 218410e51b14dda6a8ef27dee8b834f0a2005285 Mon Sep 17 00:00:00 2001 From: Qijun Date: Thu, 1 Oct 2026 06:50:44 -0700 Subject: [PATCH] fix: leave the registry first when deleting a project While another tab held a project's library, its deletion waited and the project stayed listed. Opening the project then queued behind the deletion and never finished, leaving a blank page. The project now leaves the registry first, so its address leads to another project; deleting the library is cleanup that finishes once other tabs let go. The deletion test also waited for a file list that only appears when the non-empty project happens to be the most recent one, which made it flaky. --- ui-packages/web/src/data/project-store.ts | 12 +++++----- .../src/shell/projects.integration.test.tsx | 22 +++++++++++++++++-- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ui-packages/web/src/data/project-store.ts b/ui-packages/web/src/data/project-store.ts index 0b66de9..db310d2 100644 --- a/ui-packages/web/src/data/project-store.ts +++ b/ui-packages/web/src/data/project-store.ts @@ -85,15 +85,17 @@ export const touchProject = async (id: string) => { } // A project is deleted by the page that opens after the request, before it opens any library, so -// only another tab can hold the library open. The library goes first: if it cannot be deleted, -// the project stays listed and can be retried. +// only another tab can hold the library open. The project leaves the registry first, so nothing +// opens it while its library waits for those tabs: an open would queue behind the deletion and +// never finish. Deleting the library is cleanup; if it never completes, an unlisted library is +// left taking space and nothing else. export const deleteProject = async (project: Project, onBlocked: () => void) => { - await deleteIndexedDatabase(project.databaseName, onBlocked) + const database = await openRegistry() + await database.delete('projects', project.id) Object.values(workspaceStorageBases).forEach(base => { localStorage.removeItem(workspaceStorageKey(base, project.databaseName)) }) - const database = await openRegistry() - await database.delete('projects', project.id) + await deleteIndexedDatabase(project.databaseName, onBlocked) } const pendingDeletionKey = 'gamma-reader.pending-deletion' diff --git a/ui-packages/web/src/shell/projects.integration.test.tsx b/ui-packages/web/src/shell/projects.integration.test.tsx index 65677d5..82a9d4e 100644 --- a/ui-packages/web/src/shell/projects.integration.test.tsx +++ b/ui-packages/web/src/shell/projects.integration.test.tsx @@ -1,4 +1,4 @@ -import { render, screen, within } from '@testing-library/react' +import { cleanup, render, screen, within } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { openDB } from 'idb' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -94,7 +94,8 @@ describe('projects', () => { it('deletes only what this tab asked for, once other tabs let go of it', async () => { const birds = await createProject('Bird notes') const page = visit(projectDeletionPath(birds.id)) - await screen.findByRole('list', { name: 'Files' }) + // Which project opens depends on recency, and a new one is empty, so wait for the panel only. + await screen.findByRole('complementary', { name: 'Files' }) expect(await getProject(birds.id)).not.toBeNull() page.unmount() await closeWorkspaceDatabase() @@ -110,6 +111,23 @@ describe('projects', () => { expect(await getProject(birds.id)).toBeNull() }) + it('opens another project when the address names one whose deletion is still waiting', async () => { + const birds = await createProject('Bird notes') + // Another tab holds the library, so its deletion waits. + const otherTab = await openDB(birds.databaseName) + schedulePendingDeletion(birds.id) + visit(projectDeletionPath(birds.id)) + expect( + await screen.findByText('Waiting for other tabs that have Bird notes open to close.'), + ).toBeVisible() + + // The project is already gone, so its address leads elsewhere instead of to a blank page. + cleanup() + visit(`/p/${birds.id}`) + expect(await screen.findByRole('button', { name: 'My reading' })).toBeInTheDocument() + otherTab.close() + }) + it('waits for an older tab to let go before upgrading the library, then opens it', async () => { const birds = await createProject('Bird notes') // An older page still holds the version-six library and does not know to let go.