From af8303dbf856f2b8285fe54c4411f73d7ece80ce Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 25 Apr 2026 16:49:07 +0200 Subject: [PATCH] fix(bulk-edit): auto-clear selection store when leaving /documents and /enrich MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Felix C4 — bulkSelectionStore is module-singleton; before this change it silently followed the user from /documents to /persons / /admin / etc., then reappeared as a stale count when they wandered back. Root +layout.svelte now watches page.url.pathname and clears the store the moment the user leaves the two routes that surface BulkSelectionBar. Refs #225, PR #331 Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/routes/+layout.svelte | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/frontend/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte index f3ab93b1..9a121f7a 100644 --- a/frontend/src/routes/+layout.svelte +++ b/frontend/src/routes/+layout.svelte @@ -10,6 +10,7 @@ import AppNav from './AppNav.svelte'; import UserMenu from './UserMenu.svelte'; import ConfirmDialog from '$lib/components/ConfirmDialog.svelte'; import { provideConfirmService } from '$lib/services/confirm.svelte.js'; +import { bulkSelectionStore } from '$lib/stores/bulkSelection.svelte'; let { children, data } = $props(); @@ -17,6 +18,22 @@ let { children, data } = $props(); // ConfirmDialog below reads it via getConfirmService() and renders the . provideConfirmService(); +// Auto-clear the bulk-selection store when the user leaves the routes that +// surface the BulkSelectionBar. Without this the selection silently follows +// the user to /persons / /admin etc. and reappears as a stale 3-doc count +// when they wander back to /documents — Felix C4 on PR #331. +$effect(() => { + const path = page.url.pathname; + const inBulkContext = + path === '/documents' || + path.startsWith('/documents/') || + path === '/enrich' || + path.startsWith('/enrich/'); + if (!inBulkContext && bulkSelectionStore.size > 0) { + bulkSelectionStore.clear(); + } +}); + const isAdmin = $derived( data?.user?.groups?.some((g: { permissions: string[] }) => g.permissions.includes('ADMIN')) );