Fix per-frame layout jank when focusing a toggle-input-card field#4314
Fix per-frame layout jank when focusing a toggle-input-card field#4314evanpelle wants to merge 1 commit into
Conversation
The number input in toggle-input-card was rendered conditionally
(`${checked ? html`...<input>...` : nothing}`), so enabling a toggle —
Game Timer / Gold Multiplier / Starting Gold in the single-player and
host-lobby modals — freshly inserted the <input> into the DOM. Focusing
a just-inserted input forces several ms of layout/paint every frame for
as long as it stays focused.
Keep the input permanently mounted and toggle a `hidden` class when
unchecked instead, so focusing it is always focusing an element that was
already in the DOM. Both modals share <toggle-input-card>, so this one
change fixes both.
Also restores autofocus + select of the field on enable (removed earlier
while chasing this bug) — safe now that the input is no longer freshly
inserted.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough
ChangesAuto-focus and always-mounted input in ToggleInputCard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
Problem
Focusing the number field of a
toggle-input-card(Game Timer / Gold Multiplier / Starting Gold, in both the single-player and host-lobby modals) cost several ms of layout/paint every frame for as long as the field stayed focused.Root cause
The input was rendered conditionally —
${this.checked ? html……: nothing}. Enabling a toggle therefore freshly inserts the<input>into the DOM, and focusing a just-inserted input is what forced the per-frame layout/paint. An input that was already present in the DOM doesn't do this.Fix
Keep the input permanently mounted and toggle a
hiddenclass when unchecked, instead of conditionally rendering it. Focusing it is then always focusing an element that was already there. Because both modals share<toggle-input-card>, this single change fixes both.Also restores the autofocus + select of the field on enable (it had been removed earlier while chasing this bug) — safe now that the input isn't freshly inserted.
No other UX change: the toggle behavior, checkmark, styling, and all three cards behave identically.
Testing
Hard-reload, then in both the Solo and Host-lobby modals, enable each of Game Timer / Gold Multiplier / Starting Gold, type a value, and keep the field focused — smooth, no per-frame jank, and the field autofocuses on enable.
🤖 Generated with Claude Code