🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(desktop): follow sidebar resize in the titlebar without easing (#21920)
Innei5743feca5b67
diff --git a/src/features/Electron/titlebar/NavigationBar.test.tsx b/src/features/Electron/titlebar/NavigationBar.test.tsxindex a5d898c367e..c4c892380a7 100644--- a/src/features/Electron/titlebar/NavigationBar.test.tsx+++ b/src/features/Electron/titlebar/NavigationBar.test.tsx@@ -8,6 +8,7 @@ const mocks = vi.hoisted(() => ({handlers: new Map<string, () => void>(),leftPanelVisible: false,leftPanelWidth: 0,+ navPanelResizing: false,navigate: vi.fn(),openAllAgentsDrawer: vi.fn(),}));@@ -27,7 +28,8 @@ vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({}));vi.mock('@/services/electron/system', () => ({ electronSystemService: {} }));vi.mock('@/store/global', () => ({- useGlobalStore: (selector: (state: unknown) => unknown) => selector({}),+ useGlobalStore: (selector: (state: unknown) => unknown) =>+ selector({ isNavPanelResizing: mocks.navPanelResizing }),}));vi.mock('@/store/global/selectors', () => ({systemStatusSelectors: {@@ -65,6 +67,7 @@ describe('NavigationBar tray broadcasts', () => {mocks.isMac = false;mocks.leftPanelVisible = false;mocks.leftPanelWidth = 0;+ mocks.navPanelResizing = false;vi.clearAllMocks();});@@ -99,6 +102,20 @@ describe('NavigationBar tray broadcasts', () => {expect(expanded.container.querySelector('.root')).toHaveStyle({ width: '268px' });});+ it('follows the sidebar width without a transition while it is being resized', () => {+ mocks.leftPanelVisible = true;+ mocks.leftPanelWidth = 280;+ const idle = render(<NavigationBar />);++ expect(idle.container.querySelector('.root')).not.toHaveAttribute('data-resizing');+ idle.unmount();++ mocks.navPanelResizing = true;+ const resizing = render(<NavigationBar />);++ expect(resizing.container.querySelector('.root')).toHaveAttribute('data-resizing');+ });+it('reserves the traffic light inset on macOS when the sidebar is collapsed', async () => {mocks.isMac = true;vi.resetModules();diff --git a/src/features/Electron/titlebar/NavigationBar.tsx b/src/features/Electron/titlebar/NavigationBar.tsxindex 4d235b86e89..9ef37d87c8d 100644--- a/src/features/Electron/titlebar/NavigationBar.tsx+++ b/src/features/Electron/titlebar/NavigationBar.tsx@@ -52,6 +52,10 @@ const styles = createStaticStyles(({ css, cssVar }) => ({root: css`transition: width 0.2s ${cssVar.motionEaseOut};+ &[data-resizing] {+ transition: none;+ }+@media (prefers-reduced-motion: reduce) {transition: none;}@@ -68,6 +72,7 @@ const NavigationBar = memo(() => {const activeRecentScope = useElectronStore((state) => state.activeRecentScope);const leftPanelWidth = useNavPanelWidth();+ const navPanelResizing = useGlobalStore((s) => !!s.isNavPanelResizing);useWatchBroadcast('windowFullscreenChanged', ({ isFullScreen }) => {if (isMac) setIsWindowFullScreen(isFullScreen);@@ -140,6 +145,7 @@ const NavigationBar = memo(() => {horizontalalign="center"className={styles.root}+ data-resizing={navPanelResizing || undefined}data-width={leftPanelWidth}gap={8}justify={isMac || isWindows ? 'space-between' : 'end'}diff --git a/src/features/Electron/titlebar/TabBar/TabItem.tsx b/src/features/Electron/titlebar/TabBar/TabItem.tsxindex 22a1a0f458f..0df52f50876 100644--- a/src/features/Electron/titlebar/TabBar/TabItem.tsx+++ b/src/features/Electron/titlebar/TabBar/TabItem.tsx@@ -50,6 +50,7 @@ interface TabItemProps {enterWidth: number;enterX: number;index: number;+ instant: boolean;isActive: boolean;isSplitVisible: boolean;item: ResolvedTab;@@ -86,6 +87,7 @@ const TabItem = memo<TabItemProps>(drag,enterWidth,enterX,+ instant,onActivate,onClose,onCloseOthers,@@ -132,13 +134,28 @@ const TabItem = memo<TabItemProps>(const zIndex = useMotionValue(pinned ? 1 : 0);useEffect(() => {- targetWidth.set(width);- targetInset.set(resolveTabInset(width));- }, [width, targetWidth, targetInset]);+ const nextInset = resolveTabInset(width);+ if (!instant) {+ targetWidth.set(width);+ targetInset.set(nextInset);+ return;+ }++ targetWidth.jump(width);+ springWidth.jump(width);+ targetInset.jump(nextInset);+ springInset.jump(nextInset);+ }, [width, instant, targetWidth, springWidth, targetInset, springInset]);useEffect(() => {if (!drag) {- targetX.set(x);+ if (!instant) {+ targetX.set(x);+ return;+ }++ targetX.jump(x);+ springX.jump(x);return;}@@ -161,7 +178,7 @@ const TabItem = memo<TabItemProps>(offPointer();offWidth();};- }, [drag, x, targetX, springX, springWidth]);+ }, [drag, x, instant, targetX, springX, springWidth]);// A dropped tab springs from the release point into its slot; it stays above its// neighbours until it lands, or it would slide underneath the one it overlaps.diff --git a/src/features/Electron/titlebar/TabBar/index.tsx b/src/features/Electron/titlebar/TabBar/index.tsxindex 1680f1e52b5..286cc780e74 100644--- a/src/features/Electron/titlebar/TabBar/index.tsx+++ b/src/features/Electron/titlebar/TabBar/index.tsx@@ -15,6 +15,7 @@ import { useRegisterDesktopTabHotkeys } from '@/hooks/useHotkeys/desktopTabScopeimport { usePermission } from '@/hooks/usePermission';import { electronSystemService } from '@/services/electron/system';import { useElectronStore } from '@/store/electron';+import { useGlobalStore } from '@/store/global';import { useUserStore } from '@/store/user';import { labPreferSelectors } from '@/store/user/selectors';import { electronStylish } from '@/styles/electron';@@ -45,6 +46,7 @@ const TabBar = () => {const { allowed: canCreate, reason } = usePermission('create_content');const [stripWidth, stripRef] = useStripWidth();const { tabs, activeTabId } = useResolvedTabs();+ const navPanelResizing = useGlobalStore((s) => !!s.isNavPanelResizing);const splitView = useElectronStore((s) => s.splitView);const splitViewEnabled = useUserStore(labPreferSelectors.enableDesktopSplitView);const switchTab = useElectronStore((s) => s.switchTab);@@ -105,9 +107,10 @@ const TabBar = () => {// their final geometry rather than spring in from nothing like a tab the user opened.const hasPopulated = useRef(false);const settleInstantly = !hasPopulated.current;+ const followInstantly = settleInstantly || navPanelResizing;useEffect(() => {- if (settleInstantly) {+ if (followInstantly) {targetTotal.jump(total);springTotal.jump(total);targetDividerX.jump(dividerX);@@ -127,7 +130,7 @@ const TabBar = () => {springDividerX,tabs.length,stripWidth,- settleInstantly,+ followInstantly,]);const newTabUrl = useMemo(() => {@@ -275,6 +278,7 @@ const TabBar = () => {enterWidth={settleInstantly ? placement.width : 0}enterX={settleInstantly ? placement.x : previousTotal.current}index={tabIds.indexOf(placement.id)}+ instant={navPanelResizing}isActive={placement.id === activeTabId}item={tab}key={placement.id}diff --git a/src/features/NavPanel/hooks/useNavPanel.test.ts b/src/features/NavPanel/hooks/useNavPanel.test.tsnew file mode 100644index 00000000000..035128d31e5--- /dev/null+++ b/src/features/NavPanel/hooks/useNavPanel.test.ts@@ -0,0 +1,36 @@+import { act, renderHook } from '@testing-library/react';+import { beforeEach, describe, expect, it } from 'vitest';++import { useGlobalStore } from '@/store/global';++import { useNavPanelSizeChangeHandler } from './useNavPanel';++describe('useNavPanelSizeChangeHandler', () => {+ beforeEach(() => {+ useGlobalStore.setState({ isNavPanelResizing: false, isStatusInit: true });+ });++ it('flags the nav panel as resizing until the pointer is released', () => {+ const { result } = renderHook(() => useNavPanelSizeChangeHandler());++ act(() => result.current?.({ width: 10 }, { width: 300 }));+ expect(useGlobalStore.getState().isNavPanelResizing).toBe(true);+ expect(useGlobalStore.getState().status.leftPanelWidth).toBe(300);++ act(() => {+ window.dispatchEvent(new Event('pointerup'));+ });+ expect(useGlobalStore.getState().isNavPanelResizing).toBe(false);+ });++ it('clears the flag when the pointer is cancelled', () => {+ const { result } = renderHook(() => useNavPanelSizeChangeHandler());++ act(() => result.current?.({ width: 10 }, { width: 310 }));+ act(() => {+ window.dispatchEvent(new Event('pointercancel'));+ });++ expect(useGlobalStore.getState().isNavPanelResizing).toBe(false);+ });+});diff --git a/src/features/NavPanel/hooks/useNavPanel.ts b/src/features/NavPanel/hooks/useNavPanel.tsindex ee870506790..b58a2e0e6e8 100644--- a/src/features/NavPanel/hooks/useNavPanel.ts+++ b/src/features/NavPanel/hooks/useNavPanel.ts@@ -7,9 +7,22 @@ import { useTypeScriptHappyCallback } from '@/hooks/useTypeScriptHappyCallback';import { useGlobalStore } from '@/store/global';import { systemStatusSelectors } from '@/store/global/selectors';+const endResizing = () => useGlobalStore.getState().setNavPanelResizing(false);++// DraggablePanel reports moves but not the drag ending, so the release is read off the window.+const markResizing = () => {+ const s = useGlobalStore.getState();+ if (s.isNavPanelResizing) return;++ s.setNavPanelResizing(true);+ window.addEventListener('pointerup', endResizing, { once: true });+ window.addEventListener('pointercancel', endResizing, { once: true });+};+export const useNavPanelSizeChangeHandler = (onChange?: (width: number) => void) => {const handleSizeChange: DraggablePanelProps['onSizeChange'] = useTypeScriptHappyCallback((_, size) => {+ markResizing();const width = typeof size?.width === 'string' ? Number.parseInt(size.width) : size?.width;if (!width || width < 64) return;const s = useGlobalStore.getState();diff --git a/src/store/global/actions/general.ts b/src/store/global/actions/general.tsindex ad73debe034..ae6521713f3 100644--- a/src/store/global/actions/general.ts+++ b/src/store/global/actions/general.ts@@ -223,6 +223,12 @@ export class GlobalGeneralActionImpl {);};+ setNavPanelResizing = (resizing: boolean): void => {+ if (!!this.#get().isNavPanelResizing === resizing) return;++ this.#set({ isNavPanelResizing: resizing }, false, n('setNavPanelResizing'));+ };+updateSystemStatus = (status: Partial<SystemStatus>,action?: any,diff --git a/src/store/global/initialState.ts b/src/store/global/initialState.tsindex ca558444d61..5d5d2a10d5d 100644--- a/src/store/global/initialState.ts+++ b/src/store/global/initialState.ts@@ -573,6 +573,7 @@ export const createNavigationRef = (): GlobalNavigationRef => ({ current: null }export interface GlobalState {hasNewVersion?: boolean;isMobile?: boolean;+ isNavPanelResizing?: boolean;/*** Server version is too old, does not support /api/version endpoint* Need to prompt user to update server