[priority: 4] use-toast.ts listener leak — duplicate listeners accumulate on every state change #74

Closed
opened 2026-05-19 09:09:48 +02:00 by Anexim · 2 comments
Owner

Severity: 4 — High
File: src/hooks/use-toast.ts, lines 175-182

Description:

React.useEffect(() => {
    listeners.push(setState)
    return () => {
      const index = listeners.indexOf(setState)
      if (index > -1) { listeners.splice(index, 1) }
    }
  }, [state])

The [state] dependency means every time state changes (every toast action), the effect re-runs: it pushes a new setState to listeners and removes the old one. Over time, the same component gets multiple listeners, causing duplicate renders and toast duplication.

Fix: Use [] as dependency:

React.useEffect(() => {
    listeners.push(setState)
    return () => {
      const index = listeners.indexOf(setState)
      if (index > -1) { listeners.splice(index, 1) }
    }
  }, [])
**Severity:** 4 — High **File:** `src/hooks/use-toast.ts`, lines 175-182 **Description:** ```ts React.useEffect(() => { listeners.push(setState) return () => { const index = listeners.indexOf(setState) if (index > -1) { listeners.splice(index, 1) } } }, [state]) ``` The `[state]` dependency means every time `state` changes (every toast action), the effect re-runs: it pushes a **new** `setState` to `listeners` and removes the old one. Over time, the same component gets multiple listeners, causing duplicate renders and toast duplication. **Fix:** Use `[]` as dependency: ```ts React.useEffect(() => { listeners.push(setState) return () => { const index = listeners.indexOf(setState) if (index > -1) { listeners.splice(index, 1) } } }, []) ```
Anexim added the ai:todo label 2026-05-19 09:09:48 +02:00
n8n-gitea was assigned by Anexim 2026-05-19 09:09:48 +02:00
Author
Owner

Starting work on Issue 74: use-toast.ts listener leak — duplicate listeners accumulate on every state change. Fixing by changing [state] dependency to [].

Starting work on Issue 74: use-toast.ts listener leak — duplicate listeners accumulate on every state change. Fixing by changing [state] dependency to [].
Author
Owner

Fixed: Changed useEffect dependency from [state] to [] in useToast(). This prevents duplicate listeners from accumulating on every state change.

Fixed: Changed `useEffect` dependency from `[state]` to `[]` in `useToast()`. This prevents duplicate listeners from accumulating on every state change.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#74