Skip to content

fix: file explorer doesn't update on session switch #36

Description

@saucam

Bug

When switching sessions in the web UI, the file explorer in the left sidebar does not correctly reflect the new session's working directory.

Two related issues:

1. Stale entries shown without loading indicator

If a session was previously visited, its root directory listing is cached. When switching back to it, the stale entries are shown without a loading indicator — the loadDirectory call updates them silently. This means the user can't tell whether the tree has refreshed.

2. No workdir path in the file tree header

The FileTree header only shows "Files". When switching sessions with different workdirs, there's no visual indicator of which session's directory is being browsed. Users may think the tree hasn't updated.

Root cause

In FileTree.tsx:

createEffect(
  on(focusedSessionId, (sid, prev) => {
    if (prev !== undefined && prev !== sid) {
      resetFileTreeForSession(prev as string);  // clears OLD session (memory cleanup)
    }
    if (sid) {
      void loadDirectory(sid, ".");  // starts fetch — but stale entries remain
    }
  }),
);

loadDirectory sets loading: true but does NOT clear existing entries. So the condition loading && entries === null (which shows the "loading…" indicator) is false when stale entries exist, and the stale data shows silently until the fresh response arrives.

In files.ts, loadDirectory:

setState("bySession", sessionId, path, {
  loading: true,
  error: null,
  // entries NOT cleared — stale data persists
});

Fix

  1. Add a { clearFirst?: boolean } option to loadDirectory that clears entries before fetching — used on session switch (root reload) so the loading indicator always shows.
  2. Show the current session's workdir path in the FileTree header so the user can confirm which session they're browsing.

Files

  • web/src/state/files.tsloadDirectory
  • web/src/components/files/FileTree.tsx — effect + header

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions