Skip to content

fix(chat-question-template): guard example-prompt fetch against unmount - #2086

Merged
openai0229 merged 3 commits into
OtterMind:mainfrom
Aias00:fix/2081-chatquestiontemplate-unmount
Jul 25, 2026
Merged

openai0229 merged 3 commits into
OtterMind:mainfrom
Aias00:fix/2081-chatquestiontemplate-unmount

Conversation

@Aias00

@Aias00 Aias00 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #2081

Summary

In chatQuestionTemplate, a mount-only useEffect called queryExamplePrompt, which awaits chatService.queryChatExamplePrompt({}) and then calls setExamplePromptList(res) with no mounted guard. If the component unmounted before the promise resolved, setState fired on an unmounted component. Added a mountedRef (useRef(true), set false in the mount effect's cleanup) and guard if (res && mountedRef.current) before setState, mirroring the NotificationNav pattern.

Affected surfaces

  • Frontend / Web
  • Backend / API / Storage
  • Database plugin / Driver
  • JCEF / Desktop packaging
  • CI / Build / Release
  • Documentation only

Verification

  • Commands and results:
    • npx tsc --noEmit -p chat2db-community-client/tsconfig.json — no errors for chatQuestionTemplate/index.tsx.
    • npx eslint src/pages/main/chat/chatQuestionTemplate/index.tsx — no errors.
  • Manual verification: On unmount before the fetch resolves, mountedRef.current === false skips the setExamplePromptList call.
  • UI evidence: N/A

Risk and compatibility

  • Public API or stored data: N/A.
  • Database or driver compatibility: N/A.
  • Network, privacy, or security: N/A.
  • Community / Local / Pro boundary: N/A.
  • Backward compatibility: Only skips setState after unmount; mounted behavior unchanged.

Reviewer map

  • Start here: pages/main/chat/chatQuestionTemplate/index.tsxmountedRef = useRef(true), mount useEffect sets it true and clears it in cleanup, and queryExamplePrompt guards if (res && mountedRef.current).
  • Failure condition: setExamplePromptList still fires on an unmounted component during the on-mount fetch.
  • Rollback or disable path: Revert this single commit.

Contributor declaration

  • I linked the Issue that defines this change.
  • I tested the affected behavior and reported the actual results above.
  • I did not include credentials, private data, or generated build output.
  • I disclosed substantial AI assistance below, or this PR contains no substantial AI-generated code.

AI assistance: The fix, verification, and PR description were produced with Claude Code assistance.

The mount-only effect started an async fetch that called
setExamplePromptList after await with no mounted guard, firing setState
on an unmounted component. Track a mounted ref and skip setState after
unmount.

Fixes OtterMind#2081

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 25, 2026 05:08
@Aias00
Aias00 requested a review from openai0229 as a code owner July 25, 2026 05:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@openai0229 openai0229 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the latest frontend-only head. The unmount guard is scoped correctly, and the relevant frontend build/lint/test and JavaScript CodeQL checks pass.

@openai0229
openai0229 merged commit c427e40 into OtterMind:main Jul 25, 2026
16 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

chatQuestionTemplate async fetch calls setState after unmount

3 participants