Skip to content

[BUG] NotificationBell: Missing dependency in useCallback causes potential stale closure #2142

@VIDYANKSHINI

Description

@VIDYANKSHINI

Description

There is a potential stale closure bug in the NotificationBell component. The ESLint react-hooks/exhaustive-deps rule is currently flagging a missing dependency in the useCallback hook around line 96.

Because refetch is used inside the useCallback but excluded from the dependency array, the callback might hold onto a stale reference of the refetch function. If the component's state or props change, the cached function might fail to fetch the latest notifications correctly, leading to silent failures or outdated data.

File Location

  • src/components/NotificationBell.tsx (Line 96)

Steps to Reproduce

  1. Run npm run lint in the project root.
  2. Observe the following warning in the console:
    Warning: React Hook useCallback has a missing dependency: 'refetch'. Either include it or remove the dependency array. react-hooks/exhaustive-deps

Expected Behavior

The useCallback hook should include all external variables and functions it references to prevent stale closures, ensuring that the notification fetching mechanism always executes with the most up-to-date scope.

Proposed Solution

  • Add refetch to the useCallback dependency array.
  • (Alternatively) If refetch triggers infinite loops when added, wrap the original refetch definition in a useCallback or use useRef to stabilize its reference.

Impact

This is a small but critical bug that can cause the UI to stop receiving or updating real-time notifications for the user.


I would like to work on this issue under GSSoC '26. Please assign it to me!

Metadata

Metadata

Labels

bugSomething isn't workinggssoc:assignedGSSoC: Issue assigned to a contributor

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions