Show the folder tree in a shared account

Switching to an account somebody had shared showed an empty folder tree.
Their files listed perfectly well; the sidebar beside them was blank,
with nothing to say why.

Switching accounts cleared `nodes` and `children` and stopped there. So
`treeLoaded` stayed true from the account before -- the sidebar only asks
for folders when it is false, and it never asked again -- while `dirIds`
still named the previous account's folders, which no longer resolved
against the cleared `nodes`. An empty tree either way, and no error,
because nothing had failed.

The fields that belong to one account are now named in one place,
`emptyForAccount`, and the test asserts the whole set rather than the
ones that come to mind. The bug was not bad logic, it was a field nobody
remembered when two more were added a commit earlier, and asserting the
set is the only guard that survives the next two.

Found by the person it was built for, on a real share between two
accounts, which is where it was always going to show up: the tree is
built from a query that had already run for their own account, so it
only breaks on the switch.
This commit is contained in:
2026-08-27 09:51:41 -07:00
parent c9531c577c
commit 2360e40733
2 changed files with 71 additions and 1 deletions
+17 -1
View File
@@ -75,6 +75,22 @@ export function withoutAppFolder(nodes: FileNode[]): FileNode[] {
return nodes.filter((n) => !hidden.has(n.id));
}
/**
* The state that belongs to one account, emptied when the selection moves.
*
* Every field here describes somebody's files, so none of it survives a switch
* to somebody else's. `treeLoaded` is the one that bites: leave it true and the
* sidebar never asks the new account for its folders, while `dirIds` still
* names the old account's, which no longer resolve -- so the tree is simply
* empty, with nothing to say why. That shipped, and is what this exists to stop
* happening again: the test asserts the whole set, so a field added to the
* store and forgotten here fails rather than quietly persisting across
* accounts.
*/
export function emptyForAccount(accountId: Id | null) {
return { accountId, nodes: {}, children: {}, dirIds: [], treeLoaded: false, draggingId: null, error: null };
}
export const useFiles = create<FilesState>((set, get) => ({
accountId: null,
available: false,
@@ -90,7 +106,7 @@ export const useFiles = create<FilesState>((set, get) => ({
async init() {
const accountId = useSession.getState().accountFor(CAP.filenode);
const available = Boolean(accountId && client.hasCapability(CAP.filenode));
if (accountId !== get().accountId) set({ accountId, nodes: {}, children: {} });
if (accountId !== get().accountId) set(emptyForAccount(accountId));
set({ available });
},