Skip to content

Fix React Hook dependency warnings and stale closures in ForgeMode #1383

@Abhishek2005-ard

Description

@Abhishek2005-ard

Description

In ForgeMode.jsx, there are missing dependencies in two useEffect hooks. This triggers ESLint warnings (react-hooks/exhaustive-deps) and creates the risk of state desynchronization. If the component re-renders, these effects may operate on stale closures (outdated state values), potentially causing the timer to malfunction or the audio stream to ignore volume/mute changes.

ESLint Warnings

Running npm run lint in the frontend directory outputs the following:

  • Line 135: React Hook useEffect has a missing dependency: 'handleTimerComplete'.
  • Line 157: React Hook useEffect has missing dependencies: 'isMuted', 'isRunning', and 'volume'.

Expected Behavior

All reactive variables referenced inside useEffect hooks should be properly tracked in the dependency array to ensure the effect always captures the latest state.

Proposed Solution

  1. Timer Effect: Wrap the handleTimerComplete function in a useCallback hook and safely add it to the dependency array of the interval effect.
  2. Audio Stream Effect: Refactor the audio initialization effect. Currently, it tries to access isMuted, volume, and isRunning without tracking them. We should either add these to the dependency array and properly manage re-instantiation, or remove them from this specific hook entirely since there are already separate hooks below it that handle syncing volume, muting, and playing/pausing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions