fix(wren-ui): separate instant recommend questions to new effect#1488
fix(wren-ui): separate instant recommend questions to new effect#1488andreashimin merged 1 commit intomainfrom
Conversation
WalkthroughThe changes adjust the dependency arrays in two Changes
Sequence Diagram(s)sequenceDiagram
participant UI as UI Component
participant Task as askingTask Object
participant Effect1 as useEffect (Status)
participant Effect2 as useEffect (Type)
UI->>Task: Update askingTask (status, type)
Note right of Task: Task properties updated
Task-->>Effect1: Detect change in askingTask?.status
Effect1->>UI: Execute status-dependent logic
Task-->>Effect2: Detect change in askingTask?.type
Effect2->>UI: Execute type-dependent logic
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
wren-ui/src/hooks/useAskPrompt.tsx (1)
233-238: This change effectively addresses the multiple calls issueChanging the dependency array to only include
askingTask?.typeinstead of the entireaskingTaskobject plus other dependencies solves the issue of multiple calls to the recommend questions function. This is aligned with the PR objective.However, consider two potential improvements:
Since
isNeedRecommendedQuestions()uses bothaskingTask?.typeandaskingTask?.status, you might want to includeaskingTask?.statusin the dependency array to ensure recommendations are regenerated if the status changes in a way that affects the condition.The
startRecommendedQuestionsuseCallback (line 197) only includesoriginalQuestionin its dependencies but usesthreadQuestionsinside. Consider addingthreadQuestionsto its dependency array if recommendations should update when thread questions change.useEffect(() => { // handle instant recommended questions if (isNeedRecommendedQuestions(askingTask)) { startRecommendedQuestions(); } - }, [askingTask?.type]); + }, [askingTask?.type, askingTask?.status, startRecommendedQuestions]);And for the useCallback:
const startRecommendedQuestions = useCallback(async () => { const previousQuestions = [ // slice the last 5 questions in threadQuestions ...uniq(threadQuestions).slice(-5), originalQuestion, ]; const response = await createInstantRecommendedQuestions({ variables: { data: { previousQuestions } }, }); fetchInstantRecommendedQuestions({ variables: { taskId: response.data.createInstantRecommendedQuestions.id }, }); - }, [originalQuestion]); + }, [originalQuestion, threadQuestions, createInstantRecommendedQuestions, fetchInstantRecommendedQuestions]);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
wren-ui/src/hooks/useAskPrompt.tsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
wren-ui/src/hooks/useAskPrompt.tsx (1)
231-231: Good improvement to the dependency arrayNarrowing the dependency from the entire
askingTaskobject to justaskingTask?.statusis a good optimization. This ensures the effect only reruns when the status changes, not when any other property of the task changes, reducing unnecessary executions.
Description
fix generate instant recommended question call multiple times triggered by incorrect dependency
How to reproduce
Show me database schemain prompt inputSummary by CodeRabbit