Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(app-views): persist inner sidebar preferred width to stop jumping on resize (#6535)

Seamus79ad6b579340
diff --git a/apps/web/src/components/view-shell/ViewShell.test.tsx b/apps/web/src/components/view-shell/ViewShell.test.tsx
index c95c509207..e25a232714 100644
--- a/apps/web/src/components/view-shell/ViewShell.test.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.test.tsx
@@ -5,23 +5,22 @@ import {
screen,
within,
} from '@solidjs/testing-library';
-import { type JSX, onMount } from 'solid-js';
-import { afterEach, beforeEach, expect, it, vi } from 'vitest';
+import { createSignal, type JSX, onMount } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { ViewShell } from './ViewShell';
import { ViewSidebar } from './ViewSidebar';
-const measurement = vi.hoisted(() => ({ width: 1000 }));
+const measurement = vi.hoisted(() => ({ width: (): number => 1200 }));
+
vi.mock('@solid-primitives/resize-observer', () => ({
- createElementSize: () => measurement,
-}));
-vi.mock('@core/component/Resize', () => ({
- Resize: {
- Zone: (props: { children: JSX.Element }) => <div>{props.children}</div>,
- Panel: (props: { children: JSX.Element; collapsed?: () => boolean }) => (
- <div hidden={props.collapsed?.()}>{props.children}</div>
- ),
- },
+ createElementSize: () => ({
+ get width() {
+ return measurement.width();
+ },
+ height: 800,
+ }),
}));
+
vi.mock('@ui', async () => ({
...(await import('../ui/utils/classname')),
Button: (
@@ -44,13 +43,171 @@ beforeEach(() => {
setItem: (key: string, value: string) => values.set(key, value),
removeItem: (key: string) => values.delete(key),
});
- measurement.width = 1000;
+ measurement.width = () => 1000;
});
afterEach(() => {
cleanup();
vi.unstubAllGlobals();
});
+function setup(preserveDuringResize: boolean, persistWidth = false) {
+ const [width, setWidth] = createSignal(1200);
+ const [configuredWidth, setConfiguredWidth] = createSignal(256);
+ measurement.width = width;
+ const onWidthChangeEnd = vi.fn((width: number) => {
+ if (persistWidth) setConfiguredWidth(width);
+ });
+ const view = render(() => (
+ <ViewShell.Root
+ resizable
+ asidePreferenceKey="tasks"
+ aside={{ width: configuredWidth(), preserveDuringResize }}
+ main={{ preferredWidth: 640 }}
+ >
+ <ViewShell.Aside onWidthChangeEnd={onWidthChangeEnd}>
+ <ViewSidebar.Header>
+ <ViewSidebar.Title>Tasks</ViewSidebar.Title>
+ </ViewSidebar.Header>
+ </ViewShell.Aside>
+ <ViewShell.Main>
+ <ViewShell.TopBar />
+ </ViewShell.Main>
+ </ViewShell.Root>
+ ));
+ const asideWidth = () =>
+ Number.parseFloat(
+ view.container.querySelector('[data-view-shell-aside]')!.parentElement!
+ .style.width
+ );
+ const growAside = async () => {
+ fireEvent.keyDown(view.getByRole('separator'), { key: 'ArrowRight' });
+ await Promise.resolve();
+ };
+ const dragAside = () => {
+ fireEvent(
+ view.getByRole('separator'),
+ new MouseEvent('pointerdown', { bubbles: true, button: 0, clientX: 256 })
+ );
+ fireEvent(window, new MouseEvent('pointermove', { clientX: 296 }));
+ fireEvent(window, new MouseEvent('pointerup'));
+ };
+ return {
+ ...view,
+ asideWidth,
+ growAside,
+ dragAside,
+ setWidth,
+ setConfiguredWidth,
+ onWidthChangeEnd,
+ };
+}
+
+describe('ViewShell aside resize preference', () => {
+ it('keeps a pointer resize from the sidebar minimum stable as the split grows', () => {
+ const view = setup(false);
+ view.setWidth(800);
+ expect(view.asideWidth()).toBeCloseTo(224);
+ view.dragAside();
+ expect(view.asideWidth()).toBeCloseTo(264);
+ for (const width of [801, 850, 900, 1200]) {
+ view.setWidth(width);
+ expect(view.asideWidth()).toBeCloseTo(264);
+ }
+ });
+
+ it.each([false, true])(
+ 'keeps a manual resize in a constrained split stable as the split grows (persist=%s)',
+ async (persistWidth) => {
+ const view = setup(false, persistWidth);
+ view.setWidth(890);
+ expect(view.asideWidth()).toBeCloseTo(249);
+ await view.growAside();
+ expect(view.asideWidth()).toBeCloseTo(269);
+ for (const width of [891, 900, 1000, 1200]) {
+ view.setWidth(width);
+ expect(view.asideWidth()).toBeCloseTo(269);
+ }
+ view.setWidth(880);
+ expect(view.asideWidth()).toBeCloseTo(259);
+ view.setWidth(1200);
+ expect(view.asideWidth()).toBeCloseTo(269);
+ }
+ );
+
+ it('preserves the chosen width through manual collapse and narrow overlays', async () => {
+ const view = setup(false);
+ await view.growAside();
+ fireEvent.click(view.getByRole('button', { name: 'Hide navigation' }));
+ view.setWidth(1100);
+ fireEvent.click(view.getByRole('button', { name: 'Show navigation' }));
+ expect(view.asideWidth()).toBeCloseTo(276);
+
+ view.setWidth(600);
+ expect(view.getByRole('button', { name: 'Hide navigation' })).toBeTruthy();
+ const overlay = view.container.querySelector<HTMLElement>(
+ '[data-view-shell-aside]'
+ )!;
+ expect(Number.parseFloat(overlay.style.width)).toBeCloseTo(276);
+ fireEvent.click(
+ view.getByRole('button', { name: 'Close navigation backdrop' })
+ );
+ view.setWidth(1200);
+ expect(view.getByRole('button', { name: 'Show navigation' })).toBeTruthy();
+ fireEvent.click(view.getByRole('button', { name: 'Show navigation' }));
+ expect(view.asideWidth()).toBeCloseTo(276);
+ view.setWidth(1100);
+ expect(view.asideWidth()).toBeCloseTo(276);
+ expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ });
+
+ it('remembers the width after a pointer drag', () => {
+ const view = setup(true);
+ view.dragAside();
+ expect(view.asideWidth()).toBeCloseTo(296);
+ view.setWidth(1100);
+ expect(view.asideWidth()).toBeCloseTo(296);
+ expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ });
+
+ it.each([true, false])(
+ 'keeps the chosen width when the containing split resizes (preserve=%s)',
+ async (preserve) => {
+ const view = setup(preserve);
+ expect(view.asideWidth()).toBeCloseTo(256);
+ await view.growAside();
+ expect(view.asideWidth()).toBeCloseTo(276);
+ expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ expect(view.onWidthChangeEnd.mock.calls[0][0]).toBeCloseTo(276);
+ view.setWidth(1100);
+ expect(view.asideWidth()).toBeCloseTo(276);
+ view.setWidth(1400);
+ expect(view.asideWidth()).toBeCloseTo(276);
+ expect(view.onWidthChangeEnd).toHaveBeenCalledOnce();
+ }
+ );
+
+ it('yields to the main preference, then restores the chosen width', async () => {
+ const view = setup(false);
+ await view.growAside();
+ view.setWidth(890);
+ expect(view.asideWidth()).toBeCloseTo(249);
+ view.setWidth(1200);
+ expect(view.asideWidth()).toBeCloseTo(276);
+ view.setWidth(700);
+ view.setWidth(1200);
+ expect(view.asideWidth()).toBeCloseTo(276);
+ });
+
+ it('honors a new configured width after a manual resize', async () => {
+ const view = setup(true);
+ await view.growAside();
+ view.setConfiguredWidth(300);
+ expect(view.asideWidth()).toBeCloseTo(300);
+ view.setWidth(1100);
+ expect(view.asideWidth()).toBeCloseTo(300);
+ });
+});
+
function Workspace(props: { app: string; mounted?: () => void }) {
function Content() {
onMount(() => props.mounted?.());
@@ -121,7 +278,7 @@ it('restores visibility per app after remount and persists reopening', () => {
});
it('reopens automatic narrow collapse as a dismissible overlay', () => {
- measurement.width = 600;
+ measurement.width = () => 600;
render(() => <Workspace app="documents" />);
fireEvent.click(screen.getByRole('button', { name: 'Show navigation' }));
expect(screen.getByRole('button', { name: 'Hide navigation' })).toBeTruthy();
diff --git a/apps/web/src/components/view-shell/ViewShell.tsx b/apps/web/src/components/view-shell/ViewShell.tsx
index f017aee496..1baeb4343e 100644
--- a/apps/web/src/components/view-shell/ViewShell.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.tsx
@@ -11,6 +11,7 @@ import { createElementSize } from '@solid-primitives/resize-observer';
import { Button, cn } from '@ui';
import {
type Accessor,
+ batch,
createContext,
createSignal,
createUniqueId,
@@ -314,9 +315,42 @@ function Aside(props: ViewShellAsideProps) {
'onWidthChangeEnd',
]);
const ws = useViewShellInternal();
+ const [resizedWidth, setResizedWidth] = createSignal<{
+ configuredWidth: number;
+ width: number;
+ mainWidth?: number;
+ }>();
+ const resizePreference = () => {
+ const resized = resizedWidth();
+ return resized?.configuredWidth === ws.aside.layout().width
+ ? resized
+ : undefined;
+ };
+ const preferredWidth = () => {
+ return resizePreference()?.width ?? ws.aside.layout().width;
+ };
+ const onWidthChangeEnd = (width: number) => {
+ const shellWidth = ws.width();
+ // A drag also chooses how much space Main gives up. Keeping its old soft
+ // preference would immediately undo a drag made in a constrained shell.
+ const mainWidth =
+ shellWidth !== undefined && ws.detail.placement() !== 'inline'
+ ? shellWidth - RESIZE_GUTTER - width
+ : undefined;
+ batch(() => {
+ local.onWidthChangeEnd?.(width);
+ // A consumer may persist the width back into the layout in this callback.
+ setResizedWidth({
+ configuredWidth: ws.aside.layout().width,
+ width,
+ mainWidth,
+ });
+ });
+ };
const redistributionPreferredSize = () => {
const layout = ws.aside.layout();
- if (layout.preserveDuringResize !== false) return layout.width;
+ const width = preferredWidth();
+ if (layout.preserveDuringResize !== false) return width;
const shellWidth = ws.width();
const mainLayout = ws.main.layout();
@@ -325,15 +359,21 @@ function Aside(props: ViewShellAsideProps) {
mainLayout.preferredWidth === undefined ||
ws.detail.placement() === 'inline'
) {
- return layout.width;
+ return width;
}
const availableForAside =
shellWidth -
RESIZE_GUTTER -
- Math.max(mainLayout.preferredWidth, mainLayout.min);
+ Math.max(
+ Math.min(
+ mainLayout.preferredWidth,
+ resizePreference()?.mainWidth ?? Infinity
+ ),
+ mainLayout.min
+ );
- return Math.min(layout.width, Math.max(layout.min, availableForAside));
+ return Math.min(width, Math.max(layout.min, availableForAside));
};
return (
@@ -346,9 +386,9 @@ function Aside(props: ViewShellAsideProps) {
minSize={ws.aside.layout().min}
maxSize={ws.aside.layout().max}
redistributionPreferredSize={redistributionPreferredSize()}
- target={{ kind: 'px', px: ws.aside.layout().width }}
+ target={{ kind: 'px', px: preferredWidth() }}
collapsed={() => ws.aside.isCollapsed()}
- onSizeChangeEnd={local.onWidthChangeEnd}
+ onSizeChangeEnd={onWidthChangeEnd}
>
<div
{...rest}
@@ -381,7 +421,7 @@ function Aside(props: ViewShellAsideProps) {
'relative h-full max-w-full bg-panel shadow-menu',
local.class
)}
- style={{ width: `${ws.aside.layout().width}px` }}
+ style={{ width: `${preferredWidth()}px` }}
data-view-shell-aside=""
>
{local.children}
diff --git a/apps/web/src/components/view-shell/view-shell-layout.ts b/apps/web/src/components/view-shell/view-shell-layout.ts
index 796301b1a8..b3638e6fa3 100644
--- a/apps/web/src/components/view-shell/view-shell-layout.ts
+++ b/apps/web/src/components/view-shell/view-shell-layout.ts
@@ -9,7 +9,8 @@ export type AsideLayout = {
min: number;
max: number;
/**
- * Whether automatic container resizing should preserve `width`.
+ * Whether automatic container resizing should preserve the user-resized
+ * width (or `width` before resizing).
* Set to false with a main `preferredWidth` to let the aside yield first.
*/
preserveDuringResize?: boolean;
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 11348d8a2a..e81e9a7252 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -103,6 +103,13 @@ These buttons and Home items activate on primary-button
press; keyboard activation remains supported. Home, Chat, Email,
Tasks, and other views using the shared inner
sidebar layout default to 256px; manually resized Chat widths remain saved.
+After dragging a view's inner sidebar divider (or using its arrow keys), resizing
+the containing split preserves the chosen sidebar width while space permits.
+Narrow splits may shrink or collapse the sidebar; widening restores its chosen
+width for the mounted view.
+Widening the sidebar while its split is constrained also reduces the main
+content's soft width preference, so the next split resize keeps that choice
+instead of snapping the sidebar back to its constrained width.
Email, Tasks, and Agents use the same sidebar rows, including favorites, tags,
inboxes, and recent agent chats: 32px high on desktop and 44px on touch devices,