Skip to content

chatQuestionTemplate async fetch calls setState after unmount #2081

Description

@Aias00

Chat2DB Edition

Chat2DB Community

Chat2DB Version

5.3.0

Deployment

Web

Operating System

macOS

Operating System Version

12

Database and Version

No response

Problem Summary

In chatQuestionTemplate, a mount-only useEffect calls queryExamplePrompt, which awaits chatService.queryChatExamplePrompt({}) and then calls setExamplePromptList(res) with no mounted/cancelled guard. If the component unmounts before the promise resolves, setState fires on an unmounted component.

Steps to Reproduce

  1. Open the chat question-template view.
  2. Unmount before the example-prompt fetch resolves (e.g. navigate away quickly).
  3. Observe a React unmounted-setState warning.

Expected Behavior

Guard the result with a mounted flag (e.g. let mounted = true in the mount effect, false in cleanup, check before setState), mirroring the NotificationNav pattern.

Actual Behavior

pages/main/chat/chatQuestionTemplate/index.tsx:17-26:

useEffect(() => {
  queryExamplePrompt();
}, []);

const queryExamplePrompt = async () => {
  const res = await chatService.queryChatExamplePrompt({});
  if (res) {
    setExamplePromptList(res);
  }
};

Logs

Screenshots or Additional Context

N/A

Impact

Limited or cosmetic impact

Workaround

N/A

Submission Checklist

  • I reproduced this on the selected Chat2DB edition.
  • I searched existing issues for duplicates.
  • I removed credentials and private data.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions