The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): late-contributed keybind actions reach the Keybinds settings map
teknium1eaef52371fb8
diff --git a/apps/desktop/src/app/settings/keybind-settings.late-actions.test.tsx b/apps/desktop/src/app/settings/keybind-settings.late-actions.test.tsxnew file mode 100644index 00000000000..86e3ab68d9e--- /dev/null+++ b/apps/desktop/src/app/settings/keybind-settings.late-actions.test.tsx@@ -0,0 +1,42 @@+/**+ * A keybind action contributed AFTER the settings tab mounts must appear in+ * the map. Same class as the late plugin-route bug (#109063): the component+ * subscribed to `useContributions(KEYBINDS_AREA)` but discarded the snapshot+ * and called the impure `allKeybindActions()` in render, so the React+ * Compiler memoized the list without the subscription as an input. Uses the+ * real registry + hook under the compiler-enabled vitest ui project.+ */+import { act, cleanup, render, screen } from '@testing-library/react'+import { afterEach, describe, expect, it } from 'vitest'++import { registry } from '@/contrib/registry'+import { I18nProvider } from '@/i18n'+import { KEYBINDS_AREA } from '@/lib/keybinds/actions'++import { KeybindSettings } from './keybind-settings'++afterEach(cleanup)++describe('KeybindSettings late-contributed actions', () => {+ it('lists an action whose keybind registers after mount', () => {+ render(+ <I18nProvider configClient={null} initialLocale="en">+ <KeybindSettings />+ </I18nProvider>+ )+ expect(screen.queryByText('Late Plugin Action')).toBeNull()++ let dispose = () => {}+ act(() => {+ dispose = registry.register({+ area: KEYBINDS_AREA,+ id: 'late-plugin:action',+ data: { id: 'late-plugin:action', label: 'Late Plugin Action', category: 'view', run: () => {} }+ })+ })++ expect(screen.getByText('Late Plugin Action')).toBeTruthy()++ act(() => dispose())+ })+})diff --git a/apps/desktop/src/app/settings/keybind-settings.tsx b/apps/desktop/src/app/settings/keybind-settings.tsxindex a974de48882..b65a9ecfff3 100644--- a/apps/desktop/src/app/settings/keybind-settings.tsx+++ b/apps/desktop/src/app/settings/keybind-settings.tsx@@ -37,9 +37,11 @@ export function KeybindSettings() {const bindings = useStore($bindings)const k = t.keybindsconst [collapsed, setCollapsed] = useState<ReadonlySet<string>>(new Set())- // Subscribe so contributed actions appear/disappear live in the map.- useContributions(KEYBINDS_AREA)- const actionList = allKeybindActions()+ // Subscribe so contributed actions appear/disappear live in the map. The+ // snapshot feeds the list: under React Compiler an independently called+ // allKeybindActions() stays memoized across that registration.+ const contributions = useContributions(KEYBINDS_AREA)+ const actionList = allKeybindActions(contributions)const [query, setQuery] = useState('')const openCombo = bindings[KEYBIND_PANEL_ACTION]?.[0]diff --git a/apps/desktop/src/lib/keybinds/actions.ts b/apps/desktop/src/lib/keybinds/actions.tsindex 607021d4c68..264edb7b8a9 100644--- a/apps/desktop/src/lib/keybinds/actions.ts+++ b/apps/desktop/src/lib/keybinds/actions.ts@@ -6,6 +6,7 @@// add a hotkey, add a row here and a handler there — nothing else.import { registry } from '@/contrib/registry'+import type { Contribution } from '@/contrib/types'import { IS_MAC } from './combo'@@ -202,18 +203,20 @@ export interface KeybindContribution {run: () => void}-export function contributedKeybinds(): KeybindContribution[] {- return registry- .getArea(KEYBINDS_AREA)+// React consumers pass their `useContributions(KEYBINDS_AREA)` snapshot in:+// with React Compiler enabled, an independently-called `contributedKeybinds()`+// can stay memoized across a late registration the subscription DID deliver.+export function contributedKeybinds(contributions: readonly Contribution[] = registry.getArea(KEYBINDS_AREA)): KeybindContribution[] {+ return contributions.map(c => c.data as KeybindContribution).filter(k => Boolean(k?.id && k.label) && typeof k?.run === 'function' && !ACTION_BY_ID.has(k.id))}/** Built-ins + contributed, one metadata list (panel, bindings, conflicts). */-export function allKeybindActions(): KeybindActionMeta[] {+export function allKeybindActions(contributions?: readonly Contribution[]): KeybindActionMeta[] {return [...KEYBIND_ACTIONS,- ...contributedKeybinds().map(k => ({+ ...contributedKeybinds(contributions).map(k => ({id: k.id,category: k.category ?? ('view' as const),defaults: k.defaults ?? [],