Duplicate Keyboard Shortcut Detected
Error:
[Keyboard] ⚠ Duplicate keyboard shortcut registered: shortcut-id
The Problem
An attempt was made to register a keyboard shortcut with an ID that is already in use by another shortcut.
The Why
Keyboard shortcuts must have unique IDs to:
- Prevent Conflicts: Avoid multiple actions firing for the same key combination.
- Enable Cleanup: Provide a reliable way to unregister a specific shortcut when a component unmounts.
- HMR Stability: Ensure that during development (Hot Module Replacement), shortcuts are cleaned up and re-registered correctly instead of piling up and causing unexpected behavior.
The Solution
1. Unique IDs
Ensure every shortcut you register has a unique id property:
registerShortcut({
key: “k”,
meta: true,
id: “my-unique-feature-toggle”,
action: () => { … }
});
2. Proper Cleanup (Svelte)
If you register a shortcut inside a component’s lifecycle (like onMount or $effect), you must unregister it when the component is destroyed. The registerShortcut function returns a cleanup function for this purpose.
onMount(() => {
const unregister = registerShortcut({
key: “k”,
meta: true,
id: “my-launcher-toggle”,
action: () => { … }
});
return () => {
unregister(); // Clean up on unmount
};
});
Related Concepts
- launcher-trigger-collision: Similar uniqueness requirements for Launcher view triggers.
- modules: How the Standard module system handles distributed features.
See also: https://stnd.build/duplicate-shortcut