-
Notifications
You must be signed in to change notification settings - Fork 243
fix(web): reduce unnecessary re-renders in chat reference panel #1042
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
97e438b
fix(web): reduce unnecessary re-renders in chat reference panel
brendan-kellam 5b23950
chore: update CHANGELOG for #1042
brendan-kellam 9c1c5a6
changelog
brendan-kellam f71ee48
refactor(web): move ReferencedFileSourceListItemContainer into its ow…
brendan-kellam 2ab7019
nit
brendan-kellam 03c9792
Merge branch 'main' into brendan/fix-SOU-725
brendan-kellam 0f32b5f
feedbacl
brendan-kellam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...ges/web/src/features/chat/components/chatThread/referencedFileSourceListItemContainer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| 'use client'; | ||
|
|
||
| import { getFileSource } from "@/app/api/(client)/client"; | ||
| import { VscodeFileIcon } from "@/app/components/vscodeFileIcon"; | ||
| import { Skeleton } from "@/components/ui/skeleton"; | ||
| import { isServiceError, unwrapServiceError } from "@/lib/utils"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { ReactCodeMirrorRef } from '@uiw/react-codemirror'; | ||
| import { memo, useCallback } from "react"; | ||
| import { FileReference, FileSource, Reference } from "../../types"; | ||
| import { ReferencedFileSourceListItem } from "./referencedFileSourceListItem"; | ||
| import isEqual from 'fast-deep-equal/react'; | ||
|
|
||
| export interface ReferencedFileSourceListItemContainerProps { | ||
| fileId: string; | ||
| fileSource: FileSource; | ||
| references: FileReference[]; | ||
| hoveredReference?: Reference; | ||
| selectedReference?: Reference; | ||
| onHoveredReferenceChanged: (reference?: Reference) => void; | ||
| onSelectedReferenceChanged: (reference?: Reference) => void; | ||
| isExpanded: boolean; | ||
| onExpandedChanged: (fileId: string, isExpanded: boolean) => void; | ||
| onEditorRef: (fileId: string, ref: ReactCodeMirrorRef | null) => void; | ||
| } | ||
|
|
||
| const ReferencedFileSourceListItemContainerComponent = ({ | ||
| fileId, | ||
| fileSource, | ||
| references, | ||
| hoveredReference, | ||
| selectedReference, | ||
| onHoveredReferenceChanged, | ||
| onSelectedReferenceChanged, | ||
| isExpanded, | ||
| onExpandedChanged, | ||
| onEditorRef, | ||
| }: ReferencedFileSourceListItemContainerProps) => { | ||
| const fileName = fileSource.path.split('/').pop() ?? fileSource.path; | ||
|
|
||
| const { data, isLoading, isError, error } = useQuery({ | ||
| queryKey: ['fileSource', fileSource.path, fileSource.repo, fileSource.revision], | ||
| queryFn: () => unwrapServiceError(getFileSource({ | ||
| path: fileSource.path, | ||
| repo: fileSource.repo, | ||
| ref: fileSource.revision, | ||
| })), | ||
| staleTime: Infinity, | ||
| }); | ||
|
|
||
| const handleRef = useCallback((ref: ReactCodeMirrorRef | null) => { | ||
| onEditorRef(fileId, ref); | ||
| }, [fileId, onEditorRef]); | ||
|
|
||
| const handleExpandedChanged = useCallback((isExpanded: boolean) => { | ||
| onExpandedChanged(fileId, isExpanded); | ||
| }, [fileId, onExpandedChanged]); | ||
|
|
||
| if (isLoading) { | ||
| return ( | ||
| <div className="space-y-2"> | ||
| <div className="flex items-center gap-2 p-2"> | ||
| <VscodeFileIcon fileName={fileName} className="w-4 h-4" /> | ||
| <span className="text-sm font-medium">{fileName}</span> | ||
| </div> | ||
| <Skeleton className="h-48 w-full" /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| if (isError || isServiceError(data) || !data) { | ||
| return ( | ||
| <div className="space-y-2"> | ||
| <div className="flex items-center gap-2 p-2"> | ||
| <VscodeFileIcon fileName={fileName} className="w-4 h-4" /> | ||
| <span className="text-sm font-medium">{fileName}</span> | ||
| </div> | ||
| <div className="p-4 text-sm text-destructive bg-destructive/10 rounded border"> | ||
| Failed to load file: {isServiceError(data) ? data.message : error?.message ?? 'Unknown error'} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <ReferencedFileSourceListItem | ||
| id={fileId} | ||
| code={data.source} | ||
| language={data.language} | ||
| revision={fileSource.revision} | ||
| repoName={fileSource.repo} | ||
| repoCodeHostType={data.repoCodeHostType} | ||
| repoDisplayName={data.repoDisplayName} | ||
| repoWebUrl={data.repoExternalWebUrl} | ||
| fileName={data.path} | ||
| references={references} | ||
| ref={handleRef} | ||
| onSelectedReferenceChanged={onSelectedReferenceChanged} | ||
| onHoveredReferenceChanged={onHoveredReferenceChanged} | ||
| selectedReference={selectedReference} | ||
| hoveredReference={hoveredReference} | ||
| isExpanded={isExpanded} | ||
| onExpandedChanged={handleExpandedChanged} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export const ReferencedFileSourceListItemContainer = memo(ReferencedFileSourceListItemContainerComponent, isEqual); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.