fix: resolve cascading renders and optimistic UI race conditions in u…#609
Merged
Aditya948351 merged 2 commits intoJun 14, 2026
Conversation
…seLearningProgress
Aditya948351
approved these changes
Jun 14, 2026
fd20f3e
into
devpathindcommunity-india:master
2 checks passed
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.
PR: Fix React Anti-Patterns in
useLearningProgressCloses #606
Title
fix: resolve cascading renders and optimistic UI race conditions in
useLearningProgressDescription
Issue:
setCompletedNodes([])andsetLoading(false)synchronously within theuseEffectbody when an unauthenticated user was detected. This violated React guidelines and caused thereact-hooks/set-state-in-effectlinter error.toggleNodefunction employed manual local state updates (Optimistic UI) which conflicted with theonSnapshotlistener's built-in latency compensation. This caused duplicate state triggers and potential race conditions if a network update failed.Fix:
usercontext variable instead of firing synchronous state mutations inside theuseEffect.setLoading(true)from the hook's effect body (asloadinginitializes totrueglobally, and the cleanup routine or subsequentonSnapshotadequately manages its transitions).toggleNode, completely deferring to Firestore's nativeonSnapshotlatency compensation which safely handles instantaneous local updates out-of-the-box.Type of Change
Testing
npx eslint src/hooks/useLearningProgress.tslocally and verified that thereact-hooks/set-state-in-effectrule is no longer violated.