Skip to content

fix(notification-nav): guard on-mount async queries against unmount - #2074

Merged
openai0229 merged 2 commits into
OtterMind:mainfrom
Aias00:fix/2071-notificationnav-unmount
Jul 24, 2026
Merged

fix(notification-nav): guard on-mount async queries against unmount#2074
openai0229 merged 2 commits into
OtterMind:mainfrom
Aias00:fix/2071-notificationnav-unmount

Conversation

@Aias00

@Aias00 Aias00 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Related issue

Closes #2071

Summary

NotificationNav fires three queries on mount (queryNotificationList, queryUnreadCount, queryPopNotification) that resolve into setState calls (setList, setHasUnread, setSPopOpen, setSPopData, setNoSPopOpen, setNoSPopData) with no mounted guard or AbortController. If the component unmounted before the awaits resolved, setState fired on an unmounted component. Added a mountedRef (useRef(true), set false in the mount effect's cleanup) and an early return before setState in each query function.

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 NotificationNav/index.tsx.
    • npx eslint src/components/NotificationNav/index.tsx — no errors.
  • Manual verification: On unmount before the on-mount queries resolve, the mountedRef.current === false guard skips the setState calls. The mount effect sets mountedRef.current = true on (re)mount and false on cleanup (StrictMode-safe).
  • 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: components/NotificationNav/index.tsxmountedRef = useRef(true), the mount useEffect sets it true and clears it in cleanup, and each of queryUnreadCount/queryNotificationList/queryPopNotification early-returns when !mountedRef.current.
  • Failure condition: setState still fires on an unmounted component during on-mount queries.
  • 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.

queryUnreadCount, queryNotificationList, and queryPopNotification fire on
mount and resolve into setState calls with no mounted guard. If the
component unmounted before the awaits resolved, setState fired on an
unmounted component. Track a mounted ref and skip setState after unmount.

Fixes OtterMind#2071

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

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 unmount guards around notification queries and side effects. No blocking findings; LGTM.

@openai0229
openai0229 merged commit 017b07f into OtterMind:main Jul 24, 2026
15 of 16 checks passed
@openai0229 openai0229 moved this from In Review to Done in Chat2DB Community Jul 24, 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.

NotificationNav fires async queries on mount with no unmount guard (setState after unmount)

3 participants