Skip to content

fix(wren-ui): separate instant recommend questions to new effect#1488

Merged
andreashimin merged 1 commit intomainfrom
fix/general-recommend
Mar 28, 2025
Merged

fix(wren-ui): separate instant recommend questions to new effect#1488
andreashimin merged 1 commit intomainfrom
fix/general-recommend

Conversation

@andreashimin
Copy link
Copy Markdown
Contributor

@andreashimin andreashimin commented Mar 28, 2025

Description

fix generate instant recommended question call multiple times triggered by incorrect dependency

How to reproduce

  • ask Show me database schema in prompt input
  • wait for generate instant recomended question

Summary by CodeRabbit

  • Refactor
    • Optimized internal update processes to reduce unnecessary reloads, which can lead to a more efficient and responsive experience.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2025

Walkthrough

The changes adjust the dependency arrays in two useEffect hooks within the useAskPrompt component. The first effect now depends on askingTask?.status, threadId, and checkFetchAskingStreamTask instead of the entire askingTask object. The second effect is modified to run only when askingTask?.type changes. No modifications were made to exported or public entities.

Changes

File Change Summary
wren-ui/src/hooks/useAskPrompt.tsx Refined two useEffect hooks: the first now triggers on askingTask?.status changes and the second on askingTask?.type 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
Loading

Suggested labels

wren-ui

Suggested reviewers

  • onlyjackfrost
  • fredalai

Poem

I'm a bunny hopping through the code,
Seeing changes light the dark abode.
Status and type now lead the way,
Triggering effects in a refined play.
With each hop, I cheer in delight,
Code so nimble, it's truly bright!
🐰💕

✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (1)
wren-ui/src/hooks/useAskPrompt.tsx (1)

233-238: This change effectively addresses the multiple calls issue

Changing the dependency array to only include askingTask?.type instead of the entire askingTask object 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:

  1. Since isNeedRecommendedQuestions() uses both askingTask?.type and askingTask?.status, you might want to include askingTask?.status in the dependency array to ensure recommendations are regenerated if the status changes in a way that affects the condition.

  2. The startRecommendedQuestions useCallback (line 197) only includes originalQuestion in its dependencies but uses threadQuestions inside. Consider adding threadQuestions to 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

📥 Commits

Reviewing files that changed from the base of the PR and between 39a7bea and 6c7a4bb.

📒 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 array

Narrowing the dependency from the entire askingTask object to just askingTask?.status is 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.

Copy link
Copy Markdown
Contributor

@fredalai fredalai left a comment

Choose a reason for hiding this comment

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

LGTM

@andreashimin andreashimin merged commit 37efb57 into main Mar 28, 2025
6 checks passed
@andreashimin andreashimin deleted the fix/general-recommend branch March 28, 2025 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants