Skip to content

Feat conflict detection#4

Open
solssak wants to merge 2 commits intoTanStack:mainfrom
solssak:feat-conflict-detection
Open

Feat conflict detection#4
solssak wants to merge 2 commits intoTanStack:mainfrom
solssak:feat-conflict-detection

Conversation

@solssak
Copy link

@solssak solssak commented Feb 6, 2026

🎯 Changes

This PR implements hotkey conflict detection with configurable behavior strategies, addressing the "Warn/error on conflicting shortcuts (TBD)" roadmap item from the README.

Motivation:
When multiple components or modules register the same hotkey, developers need control over how these conflicts are handled. Without this feature, duplicate registrations silently coexist, which can lead to unexpected behavior and difficult debugging.

Implementation:

  • Added ConflictBehavior type with 4 strategies: 'warn', 'error', 'replace', 'allow'
  • Added conflictBehavior option to HotkeyOptions (defaults to 'warn' for safety)
  • Implemented #findConflictingRegistration() and #handleConflict() private methods
  • Added 5 comprehensive test cases covering all scenarios
  • Fixed ESLint no-unnecessary-condition warning
    Usage:
// Default: warn but allow both registrations
manager.register('Mod+S', handler1)
manager.register('Mod+S', handler2) // ⚠️ console.warn
// Strict mode: prevent conflicts
manager.register('Mod+S', handler, { conflictBehavior: 'error' }) // throws
// Override mode: replace existing
manager.register('Mod+S', newHandler, { conflictBehavior: 'replace' })
// Silent mode: intentional duplicates
manager.register('Mod+S', handler, { conflictBehavior: 'allow' })
Note: Conflicts are only detected when both the hotkey AND target match. Different targets (e.g., document vs a specific element) don't conflict.

✅ Checklist

🚀 Release Impact

ESLint was correctly identifying that the final if statement was
unnecessary since all other cases (allow, warn, error) return early.
At this point in the code, conflictBehavior must be 'replace'.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant