Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
perf(ui): narrow closed-palette preference subscriptions
joshistoast86651096c9b5
diff --git a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsxindex f62351a0b7..8f45f622e9 100644--- a/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/CommandPaletteHotkey.browser.test.tsx@@ -8,12 +8,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { userEvent } from 'vitest/browser';const testPreferences = vi.hoisted(() => ({ customHotkeys: {} as Record<string, string[]> }));+const useWorkbenchPreferencesSpy = vi.hoisted(() => vi.fn(() => testPreferences));vi.mock('@workbench/settings/store', async (importOriginal) => ({...(await importOriginal<typeof settingsStoreModule>()),useWorkbenchPreferenceSelector: <Selected,>(selector: (preferences: typeof testPreferences) => Selected): Selected =>selector(testPreferences),- useWorkbenchPreferences: () => testPreferences,+ useWorkbenchPreferences: useWorkbenchPreferencesSpy,}));vi.mock('react-i18next', () => ({@@ -65,6 +66,7 @@ const expectPaletteState = (state: 'closed' | 'open'): void => {beforeEach(() => {testPreferences.customHotkeys = {};+ useWorkbenchPreferencesSpy.mockClear();closeCommandPalette();host = document.createElement('div');document.body.append(host);@@ -116,6 +118,16 @@ describe('Launchpad command-palette hotkeys', () => {expectPaletteState('closed');});+ it('subscribes to full preferences only while the palette is open', async () => {+ await renderLaunchpad();+ expectPaletteState('closed');+ expect(useWorkbenchPreferencesSpy).not.toHaveBeenCalled();++ await press({ code: 'KeyK', ctrlKey: true, key: 'k' });+ expectPaletteState('open');+ expect(useWorkbenchPreferencesSpy).toHaveBeenCalled();+ });+it('replaces listeners when preferences change without remounting the Launchpad host', async () => {testPreferences.customHotkeys = { 'app.openCommandPalette': ['alt+p'] };await renderLaunchpad();diff --git a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsxindex 2942a64657..90431b2dd6 100644--- a/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/LaunchpadCommandPalette.tsx@@ -2,7 +2,7 @@ import { useMountEffect } from '@platform/react/useMountEffect';import { OPEN_COMMAND_PALETTE_HOTKEY } from '@workbench/hotkeys/catalog';import { formatHotkeyForPlatform, toTinykeysBinding } from '@workbench/hotkeys/keys';import { applyCustomHotkeys } from '@workbench/hotkeys/resolve';-import { useWorkbenchPreferences } from '@workbench/settings/store';+import { useWorkbenchPreferences, useWorkbenchPreferenceSelector } from '@workbench/settings/store';import { lazy, Suspense } from 'react';import { tinykeys } from 'tinykeys';@@ -32,22 +32,28 @@ const LaunchpadCommandPaletteHotkeys = ({ keys }: { keys: readonly string[] }) =/** Lightweight Launchpad runtime and lazy dialog host. */export const LaunchpadCommandPalette = () => {const isOpen = useIsCommandPaletteOpen();- const preferences = useWorkbenchPreferences();- const paletteHotkeys = applyCustomHotkeys(OPEN_COMMAND_PALETTE_HOTKEY, preferences.customHotkeys).keys;+ const customHotkeys = useWorkbenchPreferenceSelector((preferences) => preferences.customHotkeys);+ const paletteHotkeys = applyCustomHotkeys(OPEN_COMMAND_PALETTE_HOTKEY, customHotkeys).keys;return (<><LaunchpadCommandPaletteHotkeys key={paletteHotkeys.join('\n')} keys={paletteHotkeys} />- {isOpen ? (- <Suspense fallback={null}>- <LazyLaunchpadCommandPaletteDialog- modifierKeyLabel={formatHotkeyForPlatform('mod')[0]!}- preferences={preferences}- settingsEntryDeps={SETTINGS_ENTRY_DEPS}- onClose={closeCommandPalette}- />- </Suspense>- ) : null}+ {isOpen ? <OpenLaunchpadCommandPalette /> : null}</>);};++const OpenLaunchpadCommandPalette = () => {+ const preferences = useWorkbenchPreferences();++ return (+ <Suspense fallback={null}>+ <LazyLaunchpadCommandPaletteDialog+ modifierKeyLabel={formatHotkeyForPlatform('mod')[0]!}+ preferences={preferences}+ settingsEntryDeps={SETTINGS_ENTRY_DEPS}+ onClose={closeCommandPalette}+ />+ </Suspense>+ );+};diff --git a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsxindex 5147cbdadb..49460400ad 100644--- a/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx+++ b/invokeai/frontend/webv2/src/workbench/palette/WorkbenchCommandPalette.tsx@@ -1,5 +1,3 @@-import type { WorkbenchPreferences } from '@workbench/settings/contracts';-import { requestQueueItemReveal } from '@features/queue/reveal';import { useMountEffect } from '@platform/react/useMountEffect';import { firstPartyHotkeyCatalog } from '@workbench/hotkeys/catalog';@@ -18,12 +16,13 @@ const LazyWorkbenchCommandPaletteDialog = lazy(() => import('./WorkbenchCommandP/** Lightweight route host; the palette implementation is loaded only while open. */export const WorkbenchCommandPalette = () => {const isOpen = useIsCommandPaletteOpen();- const preferences = useWorkbenchPreferences();- return isOpen ? <OpenWorkbenchCommandPalette preferences={preferences} /> : null;+ return isOpen ? <OpenWorkbenchCommandPalette /> : null;};-const OpenWorkbenchCommandPalette = ({ preferences }: { preferences: WorkbenchPreferences }) => {+const OpenWorkbenchCommandPalette = () => {+ const preferences = useWorkbenchPreferences();+useMountEffect(() => registerHotkeyModalLayer('command-palette'));return (