fix: prevent UI freezes from recomposition storms on rapid clicking (Closes #142) #144

Merged
shahondin1624 merged 1 commits from feature/issue-142-ui-freezes-on-rapid-clicking-due-to-recomposition into main 2026-04-06 17:37:09 +02:00
Owner

Summary

  • Cache CardElevation objects: Added rememberCardElevation() helper that caches the CardElevation instance across recompositions, preventing new object allocation on every composition cycle in Attribute and Talent cards
  • Memoize lambda callbacks: Wrapped onBoxClick and onHealClick lambdas in remember() in DamageMonitorPanel, preventing child DamageTrack composables from unnecessarily recomposing
  • Conditional historyVersion increment: historyVersion++ now only fires when the history dialog is actually visible, avoiding unnecessary MainScaffold recomposition on every dice roll
  • Click debouncing: Added ClickDebounce utility (300ms throttle) applied to Attribute card, Talent card, and DamageTrack box click handlers to prevent rapid state update storms

Closes #142

Test plan

  • Verify build compiles successfully on all targets
  • Verify existing tests still pass (29 pre-existing failures in VersionMigrationTest are unrelated)
  • Rapidly click Attribute cards and verify no UI freeze
  • Rapidly click damage boxes and verify no freeze
  • Verify dice roll history still updates correctly when dialog is open
  • Verify click debouncing does not prevent normal-speed interactions
## Summary - **Cache CardElevation objects**: Added `rememberCardElevation()` helper that caches the `CardElevation` instance across recompositions, preventing new object allocation on every composition cycle in Attribute and Talent cards - **Memoize lambda callbacks**: Wrapped `onBoxClick` and `onHealClick` lambdas in `remember()` in `DamageMonitorPanel`, preventing child `DamageTrack` composables from unnecessarily recomposing - **Conditional historyVersion increment**: `historyVersion++` now only fires when the history dialog is actually visible, avoiding unnecessary `MainScaffold` recomposition on every dice roll - **Click debouncing**: Added `ClickDebounce` utility (300ms throttle) applied to Attribute card, Talent card, and DamageTrack box click handlers to prevent rapid state update storms Closes #142 ## Test plan - [ ] Verify build compiles successfully on all targets - [ ] Verify existing tests still pass (29 pre-existing failures in VersionMigrationTest are unrelated) - [ ] Rapidly click Attribute cards and verify no UI freeze - [ ] Rapidly click damage boxes and verify no freeze - [ ] Verify dice roll history still updates correctly when dialog is open - [ ] Verify click debouncing does not prevent normal-speed interactions
shahondin1624 added 1 commit 2026-04-06 17:37:03 +02:00
- Cache CardElevation via rememberCardElevation() to avoid new object allocation per recomposition
- Memoize onBoxClick/onHealClick lambdas in DamageMonitorPanel with remember()
- Guard historyVersion increment behind showHistoryDialog check to avoid unnecessary recomposition
- Add ClickDebounce utility with 300ms throttle applied to Attribute, Talent, and DamageTrack clicks

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
shahondin1624 merged commit 8a0625dc3e into main 2026-04-06 17:37:09 +02:00
shahondin1624 deleted branch feature/issue-142-ui-freezes-on-rapid-clicking-due-to-recomposition 2026-04-06 17:37:09 +02:00
Sign in to join this conversation.