Skip to content

Commit e2b4d91

Browse files
committed
fix: resolve linting and TypeScript compilation errors
- Remove unused imports (React, useState, useEffect, waitFor) - Remove unused clearOnSubmit parameter from useAutosaveDraft - Prefix hasInitialDraft with _ to indicate intentionally unused - Fix useCallback dependency arrays in ChatView - Fix TypeScript error in ChatView.autosave.test.tsx
1 parent dda5c8c commit e2b4d91

File tree

5 files changed

+21
-20
lines changed

5 files changed

+21
-20
lines changed

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,10 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
177177
draftContent: inputValue,
178178
updateDraft: setInputValue,
179179
clearDraft,
180-
hasInitialDraft,
180+
hasInitialDraft: _hasInitialDraft,
181181
} = useAutosaveDraft({
182182
key: currentTaskItem?.id || "default",
183183
debounceMs: 100,
184-
clearOnSubmit: true,
185184
})
186185
const inputValueRef = useRef(inputValue)
187186
const textAreaRef = useRef<HTMLTextAreaElement>(null)
@@ -593,7 +592,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
593592
// setPrimaryButtonText(undefined)
594593
// setSecondaryButtonText(undefined)
595594
disableAutoScrollRef.current = false
596-
}, [])
595+
}, [clearDraft])
597596

598597
/**
599598
* Handles sending messages to the extension
@@ -665,7 +664,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
665664
handleChatReset()
666665
}
667666
},
668-
[handleChatReset, markFollowUpAsAnswered, sendingDisabled, clearDraft], // messagesRef and clineAskRef are stable
667+
[handleChatReset, markFollowUpAsAnswered, sendingDisabled], // messagesRef and clineAskRef are stable
669668
)
670669

671670
const handleSetChatBoxMessage = useCallback(
@@ -732,7 +731,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
732731
setClineAsk(undefined)
733732
setEnableButtons(false)
734733
},
735-
[clineAsk, startNewTask],
734+
[clineAsk, startNewTask, clearDraft],
736735
)
737736

738737
const handleSecondaryButtonClick = useCallback(
@@ -782,7 +781,7 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
782781
setClineAsk(undefined)
783782
setEnableButtons(false)
784783
},
785-
[clineAsk, startNewTask, isStreaming],
784+
[clineAsk, startNewTask, isStreaming, clearDraft],
786785
)
787786

788787
const { info: model } = useSelectedModel(apiConfiguration)
@@ -1504,7 +1503,15 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
15041503
setInputValue(preservedInput)
15051504
}
15061505
},
1507-
[handleSendMessage, setInputValue, switchToMode, alwaysAllowModeSwitch, clineAsk, markFollowUpAsAnswered],
1506+
[
1507+
handleSendMessage,
1508+
setInputValue,
1509+
switchToMode,
1510+
alwaysAllowModeSwitch,
1511+
clineAsk,
1512+
markFollowUpAsAnswered,
1513+
inputValue,
1514+
],
15081515
)
15091516

15101517
const handleBatchFileResponse = useCallback((response: { [key: string]: boolean }) => {

webview-ui/src/components/chat/__tests__/ChatView.autosave.test.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe("ChatView Autosave Integration", () => {
9595
hideAnnouncement: vi.fn(),
9696
}
9797

98-
const createMockState = (overrides: any = {}) => ({
98+
const _createMockState = (overrides: any = {}) => ({
9999
version: "1.0.0",
100100
clineMessages: [],
101101
taskHistory: [],
@@ -109,12 +109,10 @@ describe("ChatView Autosave Integration", () => {
109109
...overrides,
110110
})
111111

112-
const renderChatView = (stateOverrides: any = {}) => {
113-
const mockState = createMockState(stateOverrides)
114-
112+
const renderChatView = (_stateOverrides: any = {}) => {
115113
return render(
116114
<QueryClientProvider client={queryClient}>
117-
<ExtensionStateContextProvider initialState={mockState}>
115+
<ExtensionStateContextProvider>
118116
<ChatView {...defaultProps} />
119117
</ExtensionStateContextProvider>
120118
</QueryClientProvider>,

webview-ui/src/components/chat/__tests__/ChatView.raceCondition.spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* - Let the autosave provide recovery if something goes wrong
1818
*/
1919

20-
import React, { useState, useCallback, useEffect } from "react"
21-
import { render, screen, fireEvent, waitFor, act } from "@testing-library/react"
20+
import React, { useCallback } from "react"
21+
import { render, screen, fireEvent, act } from "@testing-library/react"
2222
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest"
2323
import { useAutosaveDraft } from "../../../hooks/useAutosaveDraft"
2424

@@ -47,7 +47,6 @@ const MessageEditorWithRaceCondition: React.FC<MessageEditorProps> = ({
4747
const { draftContent, updateDraft, clearDraft } = useAutosaveDraft({
4848
key: taskId,
4949
debounceMs: 100,
50-
clearOnSubmit: true,
5150
})
5251

5352
const handleSend = useCallback(() => {

webview-ui/src/hooks/__tests__/useAutosaveDraft.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from "react"
21
import { renderHook, act } from "@testing-library/react"
32
import { vi, describe, it, expect, beforeEach, afterEach } from "vitest"
43
import { useAutosaveDraft } from "../useAutosaveDraft"

webview-ui/src/hooks/useAutosaveDraft.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useCallback, useRef } from "react"
1+
import { useState, useEffect, useCallback, useRef } from "react"
22

33
/**
44
* Configuration options for the useAutosaveDraft hook
@@ -8,8 +8,6 @@ export interface UseAutosaveDraftOptions {
88
key: string
99
/** Debounce delay in milliseconds before saving to localStorage (default: 100ms for fast responsiveness) */
1010
debounceMs?: number
11-
/** Whether to automatically clear the draft after submission */
12-
clearOnSubmit?: boolean
1311
/** Prefix for localStorage keys to avoid collisions */
1412
storagePrefix?: string
1513
}
@@ -62,7 +60,7 @@ export interface UseAutosaveDraftReturn {
6260
* ```
6361
*/
6462
export const useAutosaveDraft = (options: UseAutosaveDraftOptions): UseAutosaveDraftReturn => {
65-
const { key, debounceMs = 100, clearOnSubmit = true, storagePrefix = "roo-draft" } = options
63+
const { key, debounceMs = 100, storagePrefix = "roo-draft" } = options
6664

6765
// Local state for the hook
6866
const [draftContent, setDraftContent] = useState<string>("")

0 commit comments

Comments
 (0)