Skip to content

fix(web): show missing-file state in browse#1381

Open
DivyamTalwar wants to merge 7 commits into
sourcebot-dev:mainfrom
DivyamTalwar:divyamtalwar/fix-827-browse-file-not-found
Open

fix(web): show missing-file state in browse#1381
DivyamTalwar wants to merge 7 commits into
sourcebot-dev:mainfrom
DivyamTalwar:divyamtalwar/fix-827-browse-file-not-found

Conversation

@DivyamTalwar

@DivyamTalwar DivyamTalwar commented Jun 28, 2026

Copy link
Copy Markdown

Fixes #827

Problem

When a user browses to a blob path that does not exist, Sourcebot currently renders the raw service error (Error loading file source: ...). This can happen after changing branches, following an old link, or browsing a file that was deleted or moved.

Root cause

CodePreviewPanel treats all getFileSource service errors the same, so FILE_NOT_FOUND never gets a browse-specific recovery UI. Preview-mode browse also needs to keep two refs separate: the content ref used for the file lookup and the active browse revision used for navigation.

Solution

  • Render a dedicated missing-file panel when getFileSource returns FILE_NOT_FOUND.
  • Preserve the active browse revision in the Return to repository root link.
  • Preserve preview-mode recovery: a missing file viewed through ?ref= still shows the preview ref, but Close preview and root navigation return to the original browse revision.
  • Keep successful preview headers anchored to the active browse revision while file content still loads from the preview ref.
  • Keep preview close controls as links instead of nesting them inside tooltip-trigger buttons.
  • Wrap long missing paths and refs so the missing-file copy stays readable in narrow panes.
  • Keep non-FILE_NOT_FOUND service errors on the existing diagnostic path.

This also avoids the review issues from the old closed PR #837: the new panel is server-rendered and the root link keeps branch context.

Tests

  • node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test 'src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx'
  • node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint
  • git diff --check origin/main...HEAD

Risk

Low. The branch is gated on the existing FILE_NOT_FOUND error code, and all other file-source errors still render their existing message. Preview ref handling is covered for both missing-file and successful-preview states.

Not tested

Manual browser navigation to a missing blob path.

Summary by CodeRabbit

  • Bug Fixes

    • The code browser now shows a clearer “File not found” state when a blob path no longer exists.
    • Added a dedicated missing-file panel that displays the requested path and a “Return to repository root” link.
    • Preview mode is now revision-aware, including a revision-specific “Close preview” link.
    • Improved error-handling so missing-file failures render before generic load errors.
  • Tests

    • Added coverage for missing-file (including preview) and successful-load states in the code preview panel.

Render a dedicated missing-file state when the browse file-source API returns FILE_NOT_FOUND, preserving the active revision in the return-to-root link.

Constraint: Prior closed PR sourcebot-dev#837 lost branch context and introduced a client-side component; this keeps the new panel server-rendered and revision-aware.

Rejected: Keeping the raw service-error text | users need a browse-specific recovery path for deleted, moved, or branch-specific files.

Confidence: high

Scope-risk: narrow

Directive: Keep other file-source service errors on the existing diagnostic error path; only FILE_NOT_FOUND should render this panel.

Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test 'src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx'

Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint

Not-tested: Manual browser navigation to a missing blob path.
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 883d8711-3e28-4115-a245-327322f1cffd

📥 Commits

Reviewing files that changed from the base of the PR and between e0605ad and 1386d65.

📒 Files selected for processing (2)
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/fileNotFoundPanel.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/fileNotFoundPanel.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx

Walkthrough

A dedicated missing-file panel is added for browse views. CodePreviewPanel now renders it for ErrorCode.FILE_NOT_FOUND responses, and tests verify the 404 UI and navigation links. A changelog entry records the change.

Changes

File Not Found State

Layer / File(s) Summary
FileNotFoundPanel component
packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/fileNotFoundPanel.tsx
Defines FileNotFoundPanel props and renders PathHeader, missing-file text with optional revision text, a preview close link, and a return-to-root link.
CodePreviewPanel error handling
packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.tsx
Imports ErrorCode and FileNotFoundPanel, reorders error checks, and renders FileNotFoundPanel for FILE_NOT_FOUND while keeping the generic file-source error path for other failures. PathHeader now receives the direct revision name.
Test coverage and changelog
packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx, CHANGELOG.md
Adds tests for FILE_NOT_FOUND rendering and preview navigation, and records the missing-file behavior in the changelog.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • brendan-kellam
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: showing a missing-file state in the browse view.
Linked Issues check ✅ Passed The PR implements the requested browse 404-style experience for missing files, replacing the raw error and preserving revision context.
Out of Scope Changes check ✅ Passed The changes stay focused on the missing-file browse UX, with only supporting tests and changelog updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

Constraint: Sourcebot requires a follow-up changelog entry for each PR under the matching Unreleased section.

Confidence: high

Scope-risk: narrow

Directive: Keep this commit scoped to the changelog entry for PR sourcebot-dev#1381.

Tested: Not run; changelog-only follow-up.

Not-tested: Runtime tests unchanged from the implementation commit.
Merge upstream main after sourcebot-dev#1376 changed the same Unreleased changelog block, keeping both release-note entries.

Constraint: GitHub reported PR sourcebot-dev#1381 as dirty against current main.\nRejected: Rewriting the open PR branch | Avoids force-pushing an existing review branch.\nConfidence: high\nScope-risk: narrow\nDirective: This merge commit should only resolve the changelog ordering conflict.\nTested: git diff --check\nNot-tested: Targeted regression test rerun follows after the merge commit.
@DivyamTalwar DivyamTalwar marked this pull request as ready for review June 28, 2026 00:42

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In
`@packages/web/src/app/`(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.tsx:
- Around line 66-69: The FileNotFoundPanel is using the fetch ref instead of the
user’s browse revision, which can send the recovery link to the wrong root when
previewRef is present. In codePreviewPanel.tsx, update the FileNotFoundPanel
call to pass the browse revision value for its revisionName prop, and introduce
a separate prop for previewRef only if the panel needs it for display copy. Use
the codePreviewPanel and FileNotFoundPanel symbols to locate and adjust the prop
wiring.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 73b03735-ab51-40db-8940-7ef21daeae8d

📥 Commits

Reviewing files that changed from the base of the PR and between 82b5c1f and 78b2eb2.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/fileNotFoundPanel.tsx

Split the ref used for failed content lookup from the ref used for browse navigation, so preview-mode 404s keep their normal return path.

Constraint: Existing previewRef semantics fetch content at the preview ref while keeping the surrounding browse context at revisionName.
Rejected: Reusing contentRef for all missing-file panel navigation | that sends preview 404 recovery links to the commit root instead of the active browse revision.
Confidence: high
Scope-risk: narrow
Directive: Keep missing-file copy tied to the failed content ref, but keep navigation tied to the browse revision.
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test 'src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx'
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint
Tested: git diff --check origin/main...HEAD
Not-tested: Manual browser navigation through a real deleted-file preview link.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 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.

Inline comments:
In
`@packages/web/src/app/`(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx:
- Around line 96-98: The root-link test in codePreviewPanel.test.tsx is
hard-coding the browse URL without the trailing slash, so it can fail even when
the component is correct. Update the expectation in the Return to repository
root assertion to match the actual output from getBrowsePath({ pathType: 'tree',
path: '' }) and keep the test aligned with the href produced by
codePreviewPanel.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b9b1d038-f9f2-4701-807e-aae9c554d298

📥 Commits

Reviewing files that changed from the base of the PR and between 78b2eb2 and 47c3083.

📒 Files selected for processing (3)
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.tsx
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/fileNotFoundPanel.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.tsx

Keep preview-mode header navigation anchored to the active browse revision while file content still loads from the preview ref.

Constraint: The browse route treats previewRef as a content fetch override, not as the surrounding browse context.
Rejected: Leaving PathHeader on contentRef | successful previews would keep breadcrumb/root navigation on the preview commit.
Confidence: high
Scope-risk: narrow
Directive: Use contentRef only for content retrieval and editor context; use revisionName for browse navigation surfaces.
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test 'src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx'
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint
Tested: git diff --check origin/main...HEAD
Not-tested: Manual browser navigation through a successful preview link.
Use the tooltip trigger as the existing link control so preview-mode close remains valid accessible markup.

Constraint: The successful-preview header now participates in the same browse-context contract as the missing-file state.
Rejected: Leaving a button wrapper around the link | creates nested interactive controls and weakens keyboard/accessibility behavior.
Confidence: high
Scope-risk: narrow
Directive: Keep tooltip triggers composed with `asChild` when the child is already the interactive control.
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test 'src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx'
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint
Tested: git diff --check origin/main...HEAD
Not-tested: Manual browser hover/focus over the preview close tooltip.
Prevent long missing paths and refs from overflowing the browse 404 panel on narrow panes.

Constraint: Missing-file copy can contain full repository paths and full preview commit refs.
Rejected: Truncating the missing path/ref | users need exact text for recovery and debugging.
Confidence: high
Scope-risk: narrow
Directive: Prefer wrapping over truncation for diagnostic identifiers in error-state copy.
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web test 'src/app/(app)/browse/[...path]/components/codePreviewPanel/codePreviewPanel.test.tsx'
Tested: node .yarn/releases/yarn-4.7.0.cjs workspace @sourcebot/web lint
Tested: git diff --check origin/main...HEAD
Not-tested: Manual browser resize with an extremely long missing path.
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.

[FR] Improve 404 page when attempting to browse file that does not exist /browse

1 participant