Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): preserve ignoreInputs across re-renders in useShortcut (#45174)

Ali Waseemfa4053cd593b
diff --git a/apps/studio/state/shortcuts/useShortcut.test.tsx b/apps/studio/state/shortcuts/useShortcut.test.tsx
index 101ffb00ba8..9275dd10bf8 100644
--- a/apps/studio/state/shortcuts/useShortcut.test.tsx
+++ b/apps/studio/state/shortcuts/useShortcut.test.tsx
@@ -118,9 +118,10 @@ describe('useShortcut', () => {
})
describe('ignoreInputs resolution', () => {
- it('defaults to undefined when no registry default and no caller override', () => {
+ it('omits the key when no registry default and no caller override (library applies its per-hotkey default)', () => {
renderHook(() => useShortcut(SHORTCUT_IDS.COMMAND_MENU_OPEN, vi.fn()))
- expect(getLastHotkeyOptions().ignoreInputs).toBeUndefined()
+ const options = getLastHotkeyOptions()
+ expect('ignoreInputs' in options).toBe(false)
})
it('uses the registry default when no caller override', () => {
diff --git a/apps/studio/state/shortcuts/useShortcut.tsx b/apps/studio/state/shortcuts/useShortcut.tsx
index 8b29baaf8fe..d5aad427798 100644
--- a/apps/studio/state/shortcuts/useShortcut.tsx
+++ b/apps/studio/state/shortcuts/useShortcut.tsx
@@ -60,7 +60,16 @@ export function useShortcut(id: ShortcutId, callback: () => void, options?: Shor
const timeout = options?.timeout ?? def.options?.timeout ?? undefined
const ignoreInputs = options?.ignoreInputs ?? def.options?.ignoreInputs
- useHotkeySequence(def.sequence, callback, { enabled, timeout, ignoreInputs })
+ // Only include `ignoreInputs` when set. The library resolves it to a concrete
+ // boolean at register time (false for Meta/Ctrl/Escape, true otherwise), but
+ // its setOptions does an object spread on every re-render — passing
+ // `ignoreInputs: undefined` would overwrite the resolved value and re-enable
+ // the input-focus guard for shortcuts that should always fire.
+ useHotkeySequence(def.sequence, callback, {
+ enabled,
+ timeout,
+ ...(ignoreInputs !== undefined && { ignoreInputs }),
+ })
// Handle overrides for command menu
const enabledInCommandMenu = enabled && (options?.registerInCommandMenu ?? false)