Skip to content

fix(web): reset quiz answer state when new quiz is generated in same chat#499

Closed
kagura-agent wants to merge 1 commit into
HKUDS:devfrom
kagura-agent:fix/quiz-state-inheritance
Closed

fix(web): reset quiz answer state when new quiz is generated in same chat#499
kagura-agent wants to merge 1 commit into
HKUDS:devfrom
kagura-agent:fix/quiz-state-inheritance

Conversation

@kagura-agent
Copy link
Copy Markdown
Contributor

Description

When generating multiple quizzes in the same chat session (e.g. using Mimic Paper mode), the later quiz inherits the answer state (submitted/not submitted) from the previous quiz instead of starting fresh.

Root Cause

QuizViewer uses useState for answer tracking, and React may reuse component instances when the component tree structure stays the same. Without a content-derived key, React preserves the internal state across different quiz question sets rendered in the same position.

Fix

Two complementary changes:

  1. Content-derived key (ChatMessages.tsx): Added a key prop to <QuizViewer> derived from the quiz question IDs/text. This forces React to unmount and remount the component when questions change, guaranteeing fresh state.

  2. Defensive state reset (QuizViewer.tsx): Added a useEffect that resets idx, answers, threads, and the reported signature when the questions signature changes. This provides defense-in-depth in case the component instance is reused.

Testing

  • TypeScript type check passes (tsc --noEmit)
  • Changes are minimal (13 lines added across 2 files), pure frontend state management fix

Related Issues

Module(s) Affected

  • web

@kagura-agent kagura-agent force-pushed the fix/quiz-state-inheritance branch 2 times, most recently from d0feb0c to 995369d Compare May 21, 2026 16:13
…chat

When multiple quizzes are generated in the same chat session, the later
quiz inherits the answer state (submitted/not submitted) from the
previous quiz instead of starting fresh.

Two fixes applied:
1. Add a content-derived key to QuizViewer so React creates a fresh
   component instance when the quiz questions change.
2. Add a defensive useEffect in QuizViewer that resets idx, answers,
   and threads when the questions signature changes.

Closes HKUDS#487
@kagura-agent kagura-agent force-pushed the fix/quiz-state-inheritance branch from 995369d to 2595b0d Compare May 21, 2026 16:20
@kagura-agent
Copy link
Copy Markdown
Contributor Author

Closing — the maintainer confirmed this is fixed in v1.4.0-beta. Thanks @pancacake! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant