Skip to content

Quiz auto-start effect may use stale callback reference #220

@navin-oss

Description

@navin-oss

Title

Quiz auto-start effect may use stale startQuiz callback causing inconsistent initialization

Description

The quiz auto-start logic inside QuizClient.tsx uses a useEffect hook that depends on multiple state values but does not include startQuiz in the dependency array.

This can cause React to capture an outdated callback reference, leading to inconsistent auto-start behavior when component state changes.

Location

app/quiz/[slug]/QuizClient.tsx

Current Code

useEffect(() => {
  ...
}, [autoStart, didAutoStart, isInline, state]);

Expected Behavior

The effect should always use the latest version of startQuiz.

Actual Behavior

The effect may execute with a stale closure and fail to trigger the latest quiz initialization logic.

Impact

  • Inconsistent quiz startup behavior
  • Potential state synchronization issues
  • React Hook dependency warning

Suggested Fix

Add startQuiz to the dependency array or memoize it using useCallback.

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