From 1b76a518940eebc00feb7460054bd9f36f7c9f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Thu, 16 Apr 2026 22:56:14 -0400 Subject: [PATCH] perf(useUIController): hoist page/panel transition objects to module scope (P2-32) Stable refs across renders eliminate unnecessary motion prop diffing. --- src/renderer/hooks/useUIController.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/renderer/hooks/useUIController.ts b/src/renderer/hooks/useUIController.ts index 63a97877..79b549fb 100644 --- a/src/renderer/hooks/useUIController.ts +++ b/src/renderer/hooks/useUIController.ts @@ -46,11 +46,14 @@ const paletteOnlyNavDefs: NavItemDef[] = [ { id: "knowledge", labelKey: "nav.knowledge", icon: BookOpen }, ]; +const NO_MOTION = { duration: 0 } as const; +const PAGE_TRANSITION = { duration: 0.32, ease: [0.16, 1, 0.3, 1] as const } as const; +const PANEL_TRANSITION = { duration: 0.28, ease: [0.16, 1, 0.3, 1] as const } as const; + export function useUIController() { const reducedMotion = useReducedMotion(); - const noMotion = { duration: 0 }; - const pageTransition = reducedMotion ? noMotion : { duration: 0.32, ease: [0.16, 1, 0.3, 1] as const }; - const panelTransition = reducedMotion ? noMotion : { duration: 0.28, ease: [0.16, 1, 0.3, 1] as const }; + const pageTransition = reducedMotion ? NO_MOTION : PAGE_TRANSITION; + const panelTransition = reducedMotion ? NO_MOTION : PANEL_TRANSITION; const locale = useAppStore((s) => s.locale); const t = useMemo(() => createTranslator(locale), [locale]);