Skip to content

Commit d001034

Browse files
authored
refactor: type improvement of file LinkPreview.tsx (RooCodeInc#2807)
1 parent 1c9bbba commit d001034

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

webview-ui/src/components/mcp/chat-display/LinkPreview.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,26 @@ interface LinkPreviewProps {
1717
url: string
1818
}
1919

20+
interface LinkPreviewState {
21+
loading: boolean
22+
error: ErrorType
23+
errorMessage: string | null
24+
ogData: OpenGraphData | null
25+
/**
26+
* Track if fetch has completed (success or error)
27+
*/
28+
hasCompletedFetch: boolean
29+
/**
30+
* Track when the fetch started
31+
*/
32+
fetchStartTime: number
33+
}
34+
2035
// Error types for better UI feedback
2136
type ErrorType = "timeout" | "network" | "general" | null
2237

2338
// Use a class component to ensure complete isolation between instances
24-
class LinkPreview extends React.Component<
25-
LinkPreviewProps,
26-
{
27-
loading: boolean
28-
error: ErrorType
29-
errorMessage: string | null
30-
ogData: OpenGraphData | null
31-
hasCompletedFetch: boolean // Track if fetch has completed (success or error)
32-
fetchStartTime: number // Track when the fetch started
33-
}
34-
> {
39+
class LinkPreview extends React.Component<LinkPreviewProps, LinkPreviewState> {
3540
private messageListener: ((event: MessageEvent) => void) | null = null
3641
private timeoutId: NodeJS.Timeout | null = null
3742
private heartbeatId: NodeJS.Timeout | null = null
@@ -60,7 +65,7 @@ class LinkPreview extends React.Component<
6065
}
6166

6267
// Prevent updates if fetch has completed
63-
shouldComponentUpdate(nextProps: LinkPreviewProps, nextState: any) {
68+
shouldComponentUpdate(nextProps: LinkPreviewProps, nextState: LinkPreviewState) {
6469
// If URL changes, allow update
6570
if (nextProps.url !== this.props.url) {
6671
return true

0 commit comments

Comments
 (0)