Skip to content

feat(local): keep which source folders are open across launches - #2441

Open
officialasishkumar wants to merge 1 commit into
MODSetter:devfrom
officialasishkumar:feat/keep-open-folders
Open

officialasishkumar wants to merge 1 commit into
MODSetter:devfrom
officialasishkumar:feat/keep-open-folders

Conversation

@officialasishkumar

@officialasishkumar officialasishkumar commented Nov 16, 2026 •

Copy link
Copy Markdown

What

The sources tree now remembers which folders are open, per workspace, across a reload, a relaunch and a switch back to the workspace.

  • features/sources/tree/expanded-folders.ts stores each workspace's open folder ids in localStorage under surfsense:expanded-folders:v1, shaped like remembered-ticks.ts beside it. Unreadable or unavailable storage falls back to every folder closed; a workspace with nothing open drops its entry.
  • features/sources/tree/use-expanded-folders.ts owns the open set for the panel: it reads the workspace's set, writes every change back, and forgets a folder once GET /folders no longer lists it. Folders have no AUTOINCREMENT, so a deleted folder's id can go to the next folder made, which would otherwise open by itself. Until the listing arrives the index has no root folder, so nothing is pruned while folders are still loading.
  • SourcesPanel takes an optional workspaceId, which the dashboard passes. Without one the open folders last only while the panel is mounted, as before, so the panel's other callers and tests are unchanged.

The row toggle, the arrow keys, and the automatic open after a move or a new folder all go through the same setter, so all of them are remembered.

Docs: docs/architecture/documents.md describes the behaviour under The sources tree and drops the Known gap "Which folders are open is not kept across a reload." The Sources user page (www/content/docs/v2/sources.mdx) says open folders stay open.

Why

Someone working inside a nested folder had to open the same chain again after every relaunch and every switch back to the workspace. 01-sources-and-folders already designs this as expanded-folders.ts, "expansion kept per workspace", and documents.md lists it under Known gaps. It is separate from the Trash work claimed in #2375.

No linked issue.

How to test

Automated, in surfsense_local/frontend:

pnpm test        # 1648 passed, 32 skipped
pnpm typecheck
pnpm lint
  • tree/use-expanded-folders.test.ts covers: closed by default, kept on reopen, kept per workspace, forgetting a folder the listing dropped (so a reused id starts closed), not pruning while folders load, nothing stored without a workspace, and unreadable storage.
  • dashboard-page.test.tsx adds "keeps a workspace's open folders when the app opens again": it opens Research, unmounts and mounts the dashboard again, and checks that Research's source still shows.
  • I checked that the tests fail without the change: with the write turned off, with pruning removed, with the loading guard removed, and without workspaceId passed from the dashboard.
  • python scripts/check_docs.py and node scripts/check_translations.mjs pass. There are no new strings.

By hand, with cd surfsense_local/electron && pnpm dev:

  1. Make a folder with a subfolder and a file in each, and open both.
  2. Quit and reopen the app. Both folders are still open.
  3. Switch to another workspace and back. The folders are still open, and the other workspace keeps its own set.
  4. Delete an open folder and make a new one. The new folder starts closed.

Summary by CodeRabbit

  • New Features
    • Open folders in Sources now stay open after closing and reopening SurfSense, separately for each workspace. Folders no longer present in the current listing are forgotten.
  • Documentation
    • Updated Sources help and known limitations to describe folder persistence and the limitation that all visible rows are rendered without windowing.

The sources tree forgot every open folder on a reload, a relaunch or a
switch back to a workspace, so someone working inside a nested folder
had to open the same chain again each time. The file-agent proposal
(01-sources-and-folders) already designs this as `expanded-folders.ts`,
"expansion kept per workspace", and documents.md listed it as a Known
gap.

- `tree/expanded-folders.ts` stores each workspace's open folder ids in
  localStorage under `surfsense:expanded-folders:v1`, shaped like the
  remembered ticks beside it. Unreadable or unavailable storage falls
  back to every folder closed, and a workspace with nothing open drops
  its entry.
- `tree/use-expanded-folders.ts` owns the open set for the panel: it
  reads the workspace's set, writes every change back, and forgets a
  folder once the folder listing no longer has it. Folders have no
  AUTOINCREMENT, so a deleted folder's id can go to the next folder
  made, which would otherwise open by itself. Until the listing arrives
  the index has no root folder, and nothing is pruned.
- `SourcesPanel` takes an optional `workspaceId`; the dashboard passes
  it. Without one the open folders last only while the panel is
  mounted, as before.

Opening a folder after a move or a new folder, the keyboard's arrows
and the row toggle all go through the same setter, so each is kept.

Docs: documents.md describes the behaviour and drops the Known gap;
the Sources user page says open folders stay open.
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

@officialasishkumar is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Expanded source folders are now saved separately for each workspace and restored across dashboard remounts. The hook removes saved folder IDs when those folders are absent from the loaded listing. The dashboard passes the active workspace ID to the sources panel.

Changes: Folder Expansion Persistence

Layer / File(s) Summary
Persist and reconcile expanded folders
surfsense_local/frontend/src/features/sources/tree/expanded-folders.ts, surfsense_local/frontend/src/features/sources/tree/use-expanded-folders.ts, surfsense_local/frontend/src/features/sources/tree/use-expanded-folders.test.ts
Storage helpers read and update expanded folder IDs per workspace. The hook restores saved IDs, removes IDs absent from a loaded folder index, and persists changes. Tests cover persistence, workspace isolation, and fallback behavior.
Connect persistence to the dashboard
surfsense_local/frontend/src/features/sources/sources-panel.tsx, surfsense_local/frontend/src/features/dashboard/dashboard-page.tsx, surfsense_local/frontend/src/features/dashboard/dashboard-page.test.tsx, docs/architecture/documents.md, www/content/docs/v2/sources.mdx
The dashboard passes the active workspace ID to SourcesPanel. A dashboard test checks that expansion remains after remount. Documentation describes workspace-specific persistence and removal of folders absent from the listing.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Merge Risk: Minimal · up to df39a

Open source folders are now remembered per workspace across launches. No merge-blocking risk was identified, and rollback is straightforward.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: open source folders are now kept across launches. The raw summary and objectives confirm that the change stores expanded folder IDs per workspace in localStorage, so t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: open source folders are now kept across launches. The raw summary and objectives confirm that the change stores expanded folder IDs per workspace in localStorage, so the title matches the changeset's primary purpose. It is specific enough for a teammate scanning history to understand the change.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7e03b16 and df39a79.

Files selected for processing: 8

  • docs/architecture/documents.md
  • surfsense_local/frontend/src/features/dashboard/dashboard-page.test.tsx
  • surfsense_local/frontend/src/features/dashboard/dashboard-page.tsx
  • surfsense_local/frontend/src/features/sources/sources-panel.tsx
  • surfsense_local/frontend/src/features/sources/tree/expanded-folders.ts
  • surfsense_local/frontend/src/features/sources/tree/use-expanded-folders.test.ts
  • surfsense_local/frontend/src/features/sources/tree/use-expanded-folders.ts
  • www/content/docs/v2/sources.mdx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant