fix(store): async batch() freezes application state updates during await - #3245
fix(store): async batch() freezes application state updates during await#3245Unnati1007 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthrough
ChangesStore batch control flow
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Karanjot786 Please review the PR, do lemme know if any changes needed and merge it under GSSoC'26 |
fix(store): async batch() freezes application state updates during await
Closes #3244
GSSoC'26
Description
This PR fixes a critical bug where passing an async function to
batch()would freeze the entire application's UI updates duringawait.Because JS is single-threaded and
batchrelies on a global_batchDepthcounter, suspending the batch meant that all unrelated state updates happening globally (from networking, user input, background timers, etc.) were accidentally intercepted and buffered until the original Promise resolved.batch()has now been aligned with standard React/Zustand behavior: it only batches synchronous operations. The Promise interception logic has been stripped, ensuringbatch()decrements its depth immediately upon function return, allowing the event loop to continue unhindered.Related Issue
Closes #3244
Which package(s)?
@termuijs/store
Type of Change
type:bug)type:feature)type:docs)type:testing)type:refactor)type:design)type:accessibility)type:performance)type:devops)type:security)Checklist
needs-starcheck blocks your merge otherwise.bun vitest runbun run buildbun run typecheckCONTRIBUTING.md.type: short description.markDirty()(if your change affects rendering).anytypes without an inline comment explaining why.GSSoC 2026 Participation
https://gssoc.girlscript.org/profile/Unnati1007Screenshots / Recordings (UI changes)
N/A - Core architecture fix.
Notes for the Reviewer
Removed the
batch.test.tsandstore.test.tstests that specifically attempted to assert thatbatchcould span Promises, as this behavior is fundamentally broken and impossible to do safely in a JS environment without heavily utilizingAsyncLocalStorage.Summary by CodeRabbit
Bug Fixes
Tests