fix(web): reset quiz answer state when new quiz is generated in same chat#499
Closed
kagura-agent wants to merge 1 commit into
Closed
fix(web): reset quiz answer state when new quiz is generated in same chat#499kagura-agent wants to merge 1 commit into
kagura-agent wants to merge 1 commit into
Conversation
d0feb0c to
995369d
Compare
…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
995369d to
2595b0d
Compare
Contributor
Author
|
Closing — the maintainer confirmed this is fixed in v1.4.0-beta. Thanks @pancacake! 🙌 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
QuizViewerusesuseStatefor answer tracking, and React may reuse component instances when the component tree structure stays the same. Without a content-derivedkey, React preserves the internal state across different quiz question sets rendered in the same position.Fix
Two complementary changes:
Content-derived key (
ChatMessages.tsx): Added akeyprop to<QuizViewer>derived from the quiz question IDs/text. This forces React to unmount and remount the component when questions change, guaranteeing fresh state.Defensive state reset (
QuizViewer.tsx): Added auseEffectthat resetsidx,answers,threads, and the reported signature when the questions signature changes. This provides defense-in-depth in case the component instance is reused.Testing
tsc --noEmit)Related Issues
Module(s) Affected
web