fix(hotkeys): prevent infinite loop in HotkeyHelpModal componentDidUpdate#4472
Conversation
…date
When HotkeyHelpModal opens with no typed hotkeys registered,
componentDidUpdate repeatedly calls setState({ currentType: null })
because the guard condition `!prevType` is always true when prevType
is already null. This triggers React's maximum update depth error.
Skip the setState call entirely when there are no types available.
The render method already returns null when currentType is falsy,
so the modal correctly won't display.
|
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 (2)
WalkthroughRefines the componentDidUpdate logic in HotkeyHelpModal to properly set currentType when hotkey types are available, and adds a test case verifying that opening the modal with no available types doesn't trigger unwanted state updates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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 |
Summary
componentDidUpdateloop inHotkeyHelpModalwhen the modal opens with no typed hotkeys registered!prevTypewas always true whenprevTypewas alreadynull, causing repeatedsetState({ currentType: null })calls and triggering React's maximum update depth error&& this.types.lengthguard sosetStateis only called when there are types to select fromRoot Cause
When
HotkeyHelpModalis opened by aHotkeyLayerthat has no hotkeys registered (e.g., in a Module Federation setup where the host and remote have separatebox-ui-elementscopies),getActiveTypes()returns an empty array. The existing code path:Sets
currentTypetonull(sincethis.typesis empty), which triggers anothercomponentDidUpdatewhereprevTypeis stillnull, creating an infinite loop.Fix
Only call
setStatewhen there are actually types available. Therender()method already returnsnullwhencurrentTypeis falsy, so the modal correctly won't display.Test Plan
setStateis not called when no types are availableSummary by CodeRabbit
Bug Fixes
Tests