fix(web): show empty-state messages in the browse file-tree panel - #1531
fix(web): show empty-state messages in the browse file-tree panel#1531Harsh23Kashyap wants to merge 4 commits into
Conversation
The browse file-tree panel previously rendered a blank scroll area when the folder contents were empty (e.g. for a freshly-created, uncommitted repository) and the generic "Error loading tree preview" text for service errors — including 404s from a typo in the repo name. Both are unhelpful. Three changes: - `pureTreePreviewPanel.tsx`: render a centered "This directory is empty." message when `items.length === 0`. The same component covers both the sub-directory case (path != '') and the repo-root case (path == ''), because a repo is just a directory at the root. - `treePreviewPanelClient.tsx`: when the folder-contents response is `[]` AND `path === ''`, render a more emphatic "This repository is empty." message (no path header, no separator) that takes the full panel. The sub-directory case still falls through to PureTreePreviewPanel with the "directory" copy. This avoids showing a path header for a non-existent root and matches the user's intent of distinguishing "no files in this repo" from "no files in this sub-directory". - `treePreviewPanel.tsx`: distinguish 404 from other service errors on `getRepoInfoByName`. A 404 means the user hit a typo in a repo name (or a config that's no longer indexed) and now shows "Repository not found." instead of the generic error text. Other status codes keep the existing "Error loading tree preview". Fixes sourcebot-dev#1530 (and addresses the user-reported screenshots in sourcebot-dev#821).
Adds `pureTreePreviewPanel.test.tsx` with one vitest case asserting
that the component renders the "This directory is empty." message
when `items={[]}`. The real FileTreeItemComponent is stubbed to a
plain `<li>` since the test only exercises the empty-state branch
(not the list rendering, which has its own coverage via the
end-to-end browse flow).
Plus a one-line CHANGELOG entry under [Unreleased] -> Fixed.
Refs sourcebot-dev#1530.
WalkthroughThe browse tree preview now shows dedicated messages for empty repositories, empty paths, and missing repositories. Tests cover empty and error states, and the changelog records the updated behavior. ChangesTree preview state handling
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant TreePreviewPanel
participant TreePreviewPanelClient
participant PureTreePreviewPanel
participant FileTree
TreePreviewPanel->>TreePreviewPanelClient: Render repository tree preview
TreePreviewPanelClient->>TreePreviewPanelClient: Check folder contents and path
alt Root path with no items
TreePreviewPanelClient-->>TreePreviewPanelClient: Render "This repository is empty."
else Non-root path with no items
TreePreviewPanelClient->>PureTreePreviewPanel: Pass empty items
PureTreePreviewPanel-->>TreePreviewPanelClient: Render empty-path message
else Non-empty path
TreePreviewPanelClient->>PureTreePreviewPanel: Pass file tree items
PureTreePreviewPanel->>FileTree: Render items
end
alt Repository lookup returns NOT_FOUND
TreePreviewPanel-->>TreePreviewPanel: Render "Repository not found."
end
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.test.tsx (1)
28-39: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd tests for the other new branches.
This test exercises only
PureTreePreviewPanel. It does not detect regressions in the root branch that omitsPathHeaderandSeparator, or in theNOT_FOUNDbranch that rendersRepository not found.. Add focused tests for the root empty response,NOT_FOUND, and non-404 service errors.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/web/src/app/`(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.test.tsx around lines 28 - 39, Add focused tests covering the remaining empty-state branches in the relevant tree preview panel test suite: verify the root empty response omits PathHeader and Separator, the NOT_FOUND response renders “Repository not found.”, and a non-404 service error follows its expected error behavior. Reuse the existing render/wrap helpers and assertions without changing the current directory-empty test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@packages/web/src/app/`(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.test.tsx:
- Around line 28-39: Add focused tests covering the remaining empty-state
branches in the relevant tree preview panel test suite: verify the root empty
response omits PathHeader and Separator, the NOT_FOUND response renders
“Repository not found.”, and a non-404 service error follows its expected error
behavior. Reuse the existing render/wrap helpers and assertions without changing
the current directory-empty test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cea463fb-85ac-4dae-bc40-d9a8ac6d69a5
📒 Files selected for processing (5)
CHANGELOG.mdpackages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.test.tsxpackages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.tsxpackages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/treePreviewPanel.tsxpackages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/treePreviewPanelClient.tsx
Bugbot finding on PR sourcebot-dev#1531: the previous copy "This directory is empty." was misleading because `git ls-tree` returns empty output for both an empty directory AND a path that doesn't exist in the tree (typo, deleted, etc.). A user navigating to a non-existent path would be told the directory is empty when in fact the path was never found. Switch to "This path has no contents in this revision." which is intentionally ambiguous — we can't tell the cases apart at this layer. The user can verify the path by looking at the repo on the code host. The root-path case ("This repository is empty.") is unchanged: a path of `''` is unambiguously the repo root, so the stronger "empty repo" copy is still accurate. Updated the test and the CHANGELOG entry to match the new copy. Refs sourcebot-dev#1531.
|
Bugbot finding addressed in 43f29491: The previous copy "This directory is empty." was misleading because Switched to "This path has no contents in this revision." which is intentionally ambiguous — we can't tell the cases apart at this layer. The user can verify the path by looking at the repo on the code host. The root-path case ("This repository is empty.") is unchanged: a path of Test + CHANGELOG updated to match the new copy. 1/1 treePreview test passes; full suite 998/998. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 43f2949. Configure here.
| <p className="text-xs"> | ||
| Once a commit lands on the default branch, its files will appear here. | ||
| </p> | ||
| </div> |
There was a problem hiding this comment.
Root empty state ignores active revision
Medium Severity
The new root empty-state UI runs whenever folderContentsResponse is [] and path === '', but the fetch uses the browse URL’s revisionName (or HEAD). An empty tree at that ref still shows “This repository is empty.” and copy about the default branch, even when the repo has files on other refs or the user is viewing a non-default revision.
Reviewed by Cursor Bugbot for commit 43f2949. Configure here.
…viewPanelClient CodeRabbit nitpick on PR sourcebot-dev#1531: the original test only covered PureTreePreviewPanel (the directory-empty case). Add focused tests for the two other new branches in treePreviewPanelClient: - Renders the "This repository is empty." message at the root path when the folder-contents response is `[]` AND `path === ''`. Asserts that the PathHeader and Separator are NOT rendered (the root empty-state takes the full panel). - Renders the "Error loading tree preview" message on a non-404 service error. The folder-contents client returns the service error object for any non-NOT_FOUND error, and the component keeps the existing copy for that case. The third new branch (NOT_FOUND in treePreviewPanel.tsx) is in a server component that imports the prisma client at module load — testing it would require mocking prisma and the `getRepoInfoByName` action, which is heavy infrastructure for a one-line branch. The NOT_FOUND case is covered by the existing pattern in the rest of the browse UI and is the same message that's used for "repo not found" elsewhere. 3/3 treePreview tests pass; full suite 999/999 (1 new test since the 998 baseline). Refs sourcebot-dev#1531.
|
CodeRabbit nitpick addressed in 15550f2e: Added two more vitest cases covering the remaining new branches in
Skipped: the NOT_FOUND branch in 3/3 treePreview tests pass; full suite 999/999. |


Summary
The browse file-tree panel previously rendered a blank scroll area when the folder contents were empty (e.g. for a freshly-created, uncommitted repository) and the generic "Error loading tree preview" text for service errors — including 404s from a typo in the repo name. Both are unhelpful.
Three changes that distinguish the cases and surface user-friendly messages:
pureTreePreviewPanel.tsx: render "This directory is empty." whenitems.length === 0. Covers both the sub-directory and repo-root cases (a repo is just a directory at the root).treePreviewPanelClient.tsx: when the response is[]ANDpath === '', render a more emphatic "This repository is empty." message (no path header, no separator) that takes the full panel.treePreviewPanel.tsx: distinguish 404 from other service errors. A 404 now shows "Repository not found." instead of the generic "Error loading tree preview" — useful when a user hits a typo in a repo name.Fixes #1530 (and addresses the user-reported screenshots in #821).
Files
packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.tsx— empty-state branch whenitems.length === 0.packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/treePreviewPanelClient.tsx— root-path-only "This repository is empty." message that takes the full panel.packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/treePreviewPanel.tsx— 404 distinction in the service-error branch.packages/web/src/app/(app)/browse/[...path]/components/treePreviewPanel/pureTreePreviewPanel.test.tsx— 1 new vitest case.CHANGELOG.md— one-line entry under[Unreleased] → Fixed.Why this is in scope
The user-facing issue is reported as confusing UX for an empty repository. The fix is purely a UI change — the data layer (
getFolderContents) already returns[]for empty repos, and thegetRepoInfoByName404 is a real user-facing condition (typo, missing config) that's been confused with a sync error. No API, no schema, no migration.Why three messages, not one
A single "This folder has no items" message would lose the distinction between the three cases the user is likely to encounter:
docs/folder with no files). The "directory" copy is accurate without alarming the user.Test coverage
1 vitest case in
pureTreePreviewPanel.test.tsx:items={[]}. The realFileTreeItemComponentis stubbed to a plain<li>since the test only exercises the empty-state branch (not the list rendering, which has its own coverage via the end-to-end browse flow).The test stubs
useIsMobileandusePathname(the latter to keep the route context stable; the empty-state branch doesn't read either, but the wrappingSidebarProviderdoes for the resize listener). The other heavy hooks the panel uses are pulled in via the import path but not exercised by the empty-state branch.1/1 test pass; full suite 998/998 (the 7 pre-existing OTel-setup failures in
ee/askmcp/...andee/permissionSyncStatus/...are unchanged by this PR).Backward compatibility
Pure UI change. The data layer is unchanged — same API responses, same shape, same error codes. Only the rendered text changes for the three empty/error cases. Existing users on non-empty repos see no change.
Risks
Minimal. The empty-state messages don't conflict with any existing copy. The 404 distinction is a small UX win. The "Once a commit lands..." copy is informative without being alarming.
Future work
POST /api/connections/{id}/syncendpoint could be wired up here, but the empty-state message is the more pressing fix.Note
Low Risk
Browse UI copy and conditional rendering only; APIs and data shapes are unchanged.
Overview
Improves browse file-tree UX when folder data is missing or empty, instead of a blank panel or a single generic error.
TreePreviewPanelnow shows "Repository not found." whengetRepoInfoByNamereturnsNOT_FOUND; other service errors still use "Error loading tree preview".TreePreviewPanelClienttreats an empty folder list at the repo root (path === '') as a dedicated full-panel state: "This repository is empty." plus guidance that files appear after a commit on the default branch (no path header).PureTreePreviewPanelshows "This path has no contents in this revision." whenitemsis empty (sub-path tree view). The copy is deliberately vague because empty dirs and missing paths both look like[]fromgit ls-tree.Vitest coverage was added for the empty-root and non-404 error paths on the client, and for the pure panel empty list. CHANGELOG documents the fix (#1530).
Reviewed by Cursor Bugbot for commit 15550f2. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit
New Features
Tests