fix(web): clear document selection when the active space changes

The bulk-selection set (`selectedDocumentIds`) lived in AppExperience and was
only cleared on explicit "clear", on successful bulk delete, or never. Switching
spaces left the previous space's selected ids in the set while the grid rendered
a different space, so the selection toolbar still showed them and "Delete
selected" would permanently delete documents from another space that the user
could no longer see.

Clear the selection (and exit selection mode) whenever the active space changes.
The functional updates return the previous reference when there is nothing to
clear, so the initial mount doesn't cause needless re-renders.
This commit is contained in:
abhay-codes07 2026-08-15 14:53:47 +05:30
parent 5ecbc26345
commit f641e3d3c0
No known key found for this signature in database

View file

@ -294,6 +294,17 @@ export function AppExperience() {
)
const [isSelectionMode, setIsSelectionMode] = useState(false)
// Selection is scoped to the documents currently on screen. When the active
// space changes the previous selection points at documents from another
// space that are no longer visible, so clear it — otherwise "Delete selected"
// would delete documents the user can't see anymore.
const activeSpaceKey = selectedProjects.join("|")
// biome-ignore lint/correctness/useExhaustiveDependencies: reset only when the space changes, not on selection edits
useEffect(() => {
setSelectedDocumentIds((prev) => (prev.size === 0 ? prev : new Set()))
setIsSelectionMode((prev) => (prev ? false : prev))
}, [activeSpaceKey])
const handleToggleSelection = useCallback((documentId: string) => {
setSelectedDocumentIds((prev) => {
const next = new Set(prev)