Skip to content

fix(browse): Fix issue where files would sometimes never load #365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

brendan-kellam
Copy link
Contributor

@brendan-kellam brendan-kellam commented Jun 25, 2025

Problem

We noticed that sometimes files would be stuck in a infinite loading state like the following:

image

This would happen randomly. Usually refreshing the page would fix it.

Solution

This PR moves the file source fetch from the client to the server. The downside of this approach is that all of the client side prefetching we were doing (with usePrefetchFolderContents.ts and usePrefetchFileSource.ts) no longer works, so now users will always see the loading spinner.

We should probably switch to links anyways (see #353), so we can probably rely on Next's built-in prefetching with the Link component..

Why was this happening in the first place?

TLDR: I'm not totally sure, but I think it's because we are using server actions incorrectly. See this issue.

I did some digging, and came across this issue that mentioned that server actions are not intended for fetching data and that you can get some unexpected behaviours when you do. This looks to be the case according to the react docs. It seems like this is one of those cases, but I'm not exactly sure why. I confirmed that this was the issue by switching over to using a fetch call and was unable to repro. Moving the data fetching to the server also fixed the issue.

As a longer-term thing, it might make sense to move away from using server actions (either altogether or for specifically data fetching) to avoid issues like this. Ideally something with as good of a DX (or better). Some options I've come across:

Summary by CodeRabbit

  • New Features

    • Introduced a new PureTreePreviewPanel component for displaying file tree previews.
  • Refactor

    • Converted several components (BrowsePage, CodePreviewPanel, TreePreviewPanel) from client-side to async server components, streamlining data fetching and removing client-side state management.
    • Simplified the useBrowseParams hook by delegating path parsing logic to a new utility function.
  • Bug Fixes

    • Improved error handling and eliminated redundant loading states in preview panels.
  • Chores

    • Removed prefetch-on-hover functionality and related hooks across file tree, breadcrumbs, and reference list components, reducing unnecessary background data fetching.
    • Deleted unused hooks for prefetching file sources and folder contents.

@brendan-kellam brendan-kellam requested a review from msukkari June 25, 2025 00:46
Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

This set of changes removes all React Query-based prefetching logic for file sources and folder contents, deletes the associated hooks, and refactors several components from client-side to server-side async components. Data fetching is now performed directly in server components, with error handling and UI loading states adjusted accordingly. Utility parsing logic is consolidated in a new function.

Changes

Files / Groups Change Summary
.../components/codePreviewPanel.tsx
.../components/treePreviewPanel.tsx
.../page.tsx
Refactored from client-side components using hooks to server-side async components with direct awaits.
.../components/pureTreePreviewPanel.tsx Added new presentational component for rendering a flat file tree preview.
.../hooks/useBrowseParams.ts
.../hooks/utils.ts
Moved browse path parsing logic into new utility function; hook now delegates parsing.
.../components/pathHeader.tsx
.../features/codeNav/components/exploreMenu/referenceList.tsx
Removed all file/folder prefetching logic and related event handlers on breadcrumbs and references.
.../features/fileTree/components/fileTreeItemComponent.tsx
.../pureFileTreePanel.tsx
Removed onMouseEnter prop and prefetch logic from file tree item components and panels.
.../components/fileSearchCommandDialog.tsx Removed prefetching and onMouseEnter logic from file search dialog and result components.
.../hooks/usePrefetchFileSource.ts
.../hooks/usePrefetchFolderContents.ts
Deleted hooks for prefetching file sources and folder contents.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BrowsePage (server)
    participant CodePreviewPanel/TreePreviewPanel (server)
    participant DataService

    User->>BrowsePage (server): Request page with params
    BrowsePage (server)->>CodePreviewPanel/TreePreviewPanel: Render with explicit props
    CodePreviewPanel/TreePreviewPanel->>DataService: await getRepoInfoByName / getFolderContents / getFileSource
    DataService-->>CodePreviewPanel/TreePreviewPanel: Return data or error
    CodePreviewPanel/TreePreviewPanel-->>BrowsePage (server): Rendered JSX
    BrowsePage (server)-->>User: Send rendered page
Loading

Possibly related PRs

Suggested reviewers

  • msukkari

Poem

In the warren of code, we hop and we sweep,
Prefetching is gone, no more data to keep.
Server-side we leap, with async delight,
Fetching just in time, in the soft server light.
With paws on the keyboard, we keep things lean—
Hopping forward, our codebase is clean! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27004e1 and f35cf47.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx (1 hunks)
  • packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*`: Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

**/*: Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

  • packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (4)
packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx (4)

5-7: LGTM: Clean imports for server component functionality

The imports are well-organized and appropriate for the server-side refactoring.


9-14: LGTM: Well-defined props interface

The interface clearly defines the required props for the server component, with appropriate optional typing for revisionName.


26-28: LGTM: Appropriate error handling for server component

The error handling is simplified and appropriate for a server component, checking both responses and returning a clear error message.


45-45: LGTM: Clean integration with new pure component

The integration with PureTreePreviewPanel is clean and follows the separation of concerns between server data fetching and client presentation logic.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (2)
packages/web/src/features/fileTree/components/pureFileTreePanel.tsx (1)

54-60: Avoid mutating React state inside transformTree

currentNode.isCollapsed = isCollapsed directly mutates a node that still belongs to the previous state tree.
Although you later spread-copy the node, the mutation happens first, so the original tree is mutated before React receives the new tree, violating React’s immutability contract and risking subtle bugs (e.g. missed re-renders in memoised children).

-            if (currentNode.path === path) {
-                currentNode.isCollapsed = isCollapsed;
-            }
-            return currentNode;
+            if (currentNode.path === path) {
+                /* return a new object – never mutate the existing one */
+                return { ...currentNode, isCollapsed };
+            }
+            return currentNode;
packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx (1)

2-6: Remove unused imports from client-side version.

These imports are no longer needed after the conversion to a server component:

  • useBrowseParams (now receives props)
  • useQuery (now uses direct await)
  • useDomain (now receives domain as prop)
  • Loader2 (loading handled by Suspense in parent)
-import { useBrowseParams } from "@/app/[domain]/browse/hooks/useBrowseParams";
-import { useQuery } from "@tanstack/react-query";
-import { getFileSource } from "@/features/search/fileSourceApi";
-import { useDomain } from "@/hooks/useDomain";
-import { Loader2 } from "lucide-react";
+import { getFileSource } from "@/features/search/fileSourceApi";
🧹 Nitpick comments (5)
packages/web/src/features/fileTree/components/pureFileTreePanel.tsx (2)

95-98: Redundant key prop duplication

Both the React.Fragment (line 95) and the nested FileTreeItemComponent (line 97) receive the same key={node.path}.
The extra key on the child component is superfluous and can be safely removed to keep the markup tidy.

-<React.Fragment key={node.path}>
-    <FileTreeItemComponent
-        key={node.path}
+<React.Fragment key={node.path}>
+    <FileTreeItemComponent

112-113: renderTree dependency list may cause unnecessary re-creations

renderTree depends on scrollAreaRef (passed to children) but the ref is omitted from the dependency array.
While useRef objects are stable, future changes (e.g. swapping to useState or replacing the ref) would silently break memoisation.
For completeness and future-proofing, include it:

-    }, [path, onNodeClicked]);
+    }, [path, onNodeClicked, scrollAreaRef]);
packages/web/src/app/[domain]/browse/hooks/utils.ts (2)

3-3: Fix typo in variable name.

The variable name sentinalIndex should be sentinelIndex (missing 'e').

-    const sentinalIndex = pathParam.search(/\/-\/(tree|blob)\//);
+    const sentinelIndex = pathParam.search(/\/-\/(tree|blob)\//);

You'll also need to update the usage on lines 4, 8, and 13.


16-16: Fix typo in comment.

The comment mentions decodedURIComponent but should be decodeURIComponent.

-        // @note: decodedURIComponent is needed here incase the path contains a space.
+        // @note: decodeURIComponent is needed here in case the path contains a space.
packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx (1)

25-27: Enhance error handling with more descriptive messages

The current error handling doesn't provide enough context about which operation failed or why.

     if (isServiceError(folderContentsResponse) || isServiceError(repoInfoResponse)) {
-        return <div>Error loading tree preview</div>
+        const errorMessage = isServiceError(repoInfoResponse) 
+            ? `Failed to load repository information for ${repoName}`
+            : `Failed to load folder contents at ${path}`;
+        return <div className="p-4 text-red-500">{errorMessage}</div>
     }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebf6721 and 27004e1.

📒 Files selected for processing (13)
  • packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx (2 hunks)
  • packages/web/src/app/[domain]/browse/[...path]/components/pureTreePreviewPanel.tsx (1 hunks)
  • packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx (2 hunks)
  • packages/web/src/app/[domain]/browse/[...path]/page.tsx (1 hunks)
  • packages/web/src/app/[domain]/browse/components/fileSearchCommandDialog.tsx (0 hunks)
  • packages/web/src/app/[domain]/browse/hooks/useBrowseParams.ts (1 hunks)
  • packages/web/src/app/[domain]/browse/hooks/utils.ts (1 hunks)
  • packages/web/src/app/[domain]/components/pathHeader.tsx (0 hunks)
  • packages/web/src/ee/features/codeNav/components/exploreMenu/referenceList.tsx (0 hunks)
  • packages/web/src/features/fileTree/components/fileTreeItemComponent.tsx (0 hunks)
  • packages/web/src/features/fileTree/components/pureFileTreePanel.tsx (1 hunks)
  • packages/web/src/hooks/usePrefetchFileSource.ts (0 hunks)
  • packages/web/src/hooks/usePrefetchFolderContents.ts (0 hunks)
💤 Files with no reviewable changes (6)
  • packages/web/src/features/fileTree/components/fileTreeItemComponent.tsx
  • packages/web/src/app/[domain]/components/pathHeader.tsx
  • packages/web/src/hooks/usePrefetchFolderContents.ts
  • packages/web/src/hooks/usePrefetchFileSource.ts
  • packages/web/src/app/[domain]/browse/components/fileSearchCommandDialog.tsx
  • packages/web/src/ee/features/codeNav/components/exploreMenu/referenceList.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*`: Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

**/*: Filenames should always be camelCase. Exception: if there are filenames in the same directory with a format other than camelCase, use that format to keep things consistent.

  • packages/web/src/features/fileTree/components/pureFileTreePanel.tsx
  • packages/web/src/app/[domain]/browse/[...path]/components/pureTreePreviewPanel.tsx
  • packages/web/src/app/[domain]/browse/hooks/utils.ts
  • packages/web/src/app/[domain]/browse/hooks/useBrowseParams.ts
  • packages/web/src/app/[domain]/browse/[...path]/page.tsx
  • packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx
  • packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (7)
packages/web/src/app/[domain]/browse/hooks/utils.ts (1)

2-37: LGTM - Well-structured utility function.

The path parsing logic is well-implemented with proper error handling and clear separation of concerns. This centralizes the parsing logic effectively, supporting the broader refactoring goals.

packages/web/src/app/[domain]/browse/[...path]/components/pureTreePreviewPanel.tsx (1)

1-46: LGTM - Well-designed pure presentational component.

This component provides a clean separation of concerns by accepting data as props while handling UI interactions through hooks. The use of useCallback for the click handler is appropriate for performance optimization.

packages/web/src/app/[domain]/browse/hooks/useBrowseParams.ts (1)

8-17: LGTM - Good refactoring to centralize parsing logic.

The simplification of this hook by delegating to the utility function is a solid improvement. The memoization ensures the parsing only happens when the pathname changes.

packages/web/src/app/[domain]/browse/[...path]/page.tsx (2)

14-17: LGTM - Clean server component conversion.

The conversion to an async server component with explicit props is well-executed. Using decodeURIComponent on the joined path and the utility function for parsing is the correct approach.


20-25: LGTM - Appropriate loading state handling.

The Suspense fallback with loading spinner provides good user feedback during data fetching. This aligns with the PR's goal of moving loading states to the server side.

packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx (1)

21-40: LGTM - Excellent server component conversion.

The conversion from React Query to direct await calls is well-implemented. The sequential data fetching, error handling with isServiceError, and explicit props pattern align perfectly with the PR's objectives to fix the loading issues.

packages/web/src/app/[domain]/browse/[...path]/components/treePreviewPanel.tsx (1)

29-46: Clean separation of concerns!

The refactoring to delegate rendering to PureTreePreviewPanel while keeping data fetching in the server component is well-structured and aligns with Next.js best practices.

@brendan-kellam
Copy link
Contributor Author

todo: fix bug with navigating to repository root.
image

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.

2 participants