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(layout): prevent home content from animating on open (#9401)

dev-rbfbb2deb8a202
diff --git a/apps/web/src/components/view-shell/README.md b/apps/web/src/components/view-shell/README.md
index f90233aa77..8dc97a5175 100644
--- a/apps/web/src/components/view-shell/README.md
+++ b/apps/web/src/components/view-shell/README.md
@@ -34,11 +34,12 @@ align trailing controls by their outer edges or offset an individual icon.
Desktop multi-split close controls live in the outer frame corner. The inherited split controller sets `closeButtonPlacement` to `frame` to suppress duplicate header/sidebar close buttons; touch layouts retain header placement.
-Automatic navigation closure at the narrow breakpoint keeps the docked Resize
-panel mounted while its width closes over 140ms. Main expands alongside the
-sidebar without writing the saved wide preference. An explicit overlay opening
-or required navigation takes priority over the exit, and a quick return to wide
-reuses the docked panel.
+Automatic navigation closure after the first measurable layout keeps the docked
+Resize panel mounted while its width closes over 140ms. The initial layout,
+including a view becoming measurable after mounting at zero width, settles
+without motion. Main expands alongside later sidebar closures without writing
+the saved wide preference. An explicit overlay opening or required navigation
+takes priority over the exit, and a quick return to wide reuses the docked panel.
A single host phase (`docked`, `closing`, or `overlay`) controls mounting.
Breakpoint transitions own host changes; pin changes only animate the active
host and do not cancel a pending narrow exit.
diff --git a/apps/web/src/components/view-shell/ViewShell.test.tsx b/apps/web/src/components/view-shell/ViewShell.test.tsx
index 67c55bf123..a6888e228f 100644
--- a/apps/web/src/components/view-shell/ViewShell.test.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.test.tsx
@@ -21,7 +21,9 @@ import {
} from './ViewShell';
import { ViewSidebar } from './ViewSidebar';
-const measurement = vi.hoisted(() => ({ width: (): number => 1200 }));
+const measurement = vi.hoisted(() => ({
+ width: (): number | undefined => 1200,
+}));
vi.mock('@core/hotkey/hotkeys', () => ({ registerHotkey: vi.fn() }));
@@ -900,6 +902,34 @@ describe('automatic docked navigation exit', () => {
}
});
+ it.each([
+ [undefined, 600],
+ [undefined, 1000],
+ [0, 600],
+ [0, 1000],
+ ] as const)(
+ 'settles an initial width of %s at %s without animating the Home content',
+ async (initialWidth, settledWidth) => {
+ const [width, setWidth] = createSignal<number | undefined>(initialWidth);
+ measurement.width = width;
+ const view = render(() => <Workspace app="home" />);
+ const savePreference = vi.spyOn(localStorage, 'setItem');
+
+ setWidth(settledWidth);
+ await Promise.resolve();
+
+ expect(animate).not.toHaveBeenCalled();
+ expect(
+ view.container.querySelectorAll('[data-view-shell-aside]')
+ ).toHaveLength(settledWidth === 600 ? 0 : 1);
+ expect(savePreference).not.toHaveBeenCalled();
+
+ setWidth(settledWidth === 600 ? 1000 : 600);
+ await Promise.resolve();
+ expect(animate).toHaveBeenCalled();
+ }
+ );
+
it('retains and collapses the docked host until its 140ms exit finishes', async () => {
const [width, setWidth] = createSignal(1000);
measurement.width = width;
@@ -946,28 +976,34 @@ describe('automatic docked navigation exit', () => {
expect(savePreference).not.toHaveBeenCalled();
});
- it('ignores stale exits after a rapid wide reversal and reuses the docked host', async () => {
- const [width, setWidth] = createSignal(1000);
- measurement.width = width;
- const view = render(() => <Workspace app="tasks" />);
- const docked = view.container.querySelector<HTMLElement>(
- '[data-view-shell-aside]'
- )!.parentElement!;
- setWidth(600);
- await Promise.resolve();
- const stale = animations.find(({ target }) => target === docked)?.animation;
- setWidth(1000);
- stale?.onfinish?.(new Event('finish') as AnimationPlaybackEvent);
- await Promise.resolve();
- expect(docked.isConnected).toBe(true);
- expect(docked.classList.contains('hidden')).toBe(false);
- expect(
- view.container.querySelectorAll('[data-view-shell-aside]')
- ).toHaveLength(1);
- expect(
- screen.getByRole('button', { name: 'Hide navigation' })
- ).toBeTruthy();
- });
+ it.each([undefined, 0, 600])(
+ 'ignores stale exits after width %s during a wide reversal',
+ async (intermediateWidth) => {
+ const [width, setWidth] = createSignal<number | undefined>(1000);
+ measurement.width = width;
+ const view = render(() => <Workspace app="tasks" />);
+ const docked = view.container.querySelector<HTMLElement>(
+ '[data-view-shell-aside]'
+ )!.parentElement!;
+ setWidth(600);
+ await Promise.resolve();
+ const stale = animations.find(
+ ({ target }) => target === docked
+ )?.animation;
+ setWidth(intermediateWidth);
+ setWidth(1000);
+ stale?.onfinish?.(new Event('finish') as AnimationPlaybackEvent);
+ await Promise.resolve();
+ expect(docked.isConnected).toBe(true);
+ expect(docked.classList.contains('hidden')).toBe(false);
+ expect(
+ view.container.querySelectorAll('[data-view-shell-aside]')
+ ).toHaveLength(1);
+ expect(
+ screen.getByRole('button', { name: 'Hide navigation' })
+ ).toBeTruthy();
+ }
+ );
it('cancels an exit before its animation starts when the breakpoint reverses', async () => {
const [width, setWidth] = createSignal(1000);
diff --git a/apps/web/src/components/view-shell/ViewShell.tsx b/apps/web/src/components/view-shell/ViewShell.tsx
index c19ee29a70..ce3a108f8c 100644
--- a/apps/web/src/components/view-shell/ViewShell.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.tsx
@@ -23,6 +23,7 @@ import {
type ComponentProps,
createComputed,
createContext,
+ createMemo,
createSignal,
createUniqueId,
type JSX,
@@ -289,34 +290,44 @@ function Root(props: ViewShellRootProps) {
} else setWideAsideCollapsed(!open);
});
};
+ // Keep the last measured breakpoint while the view is detached or hidden.
+ const measuredLayoutBreakpoint = createMemo<boolean | undefined>(
+ (previous) => {
+ const currentWidth = width();
+ return currentWidth === undefined || currentWidth <= 0
+ ? previous
+ : atLayoutBreakpoint();
+ }
+ );
// Measure the old host before the slots react to a breakpoint transition.
createComputed(
- on(
- atLayoutBreakpoint,
- (narrow, previous) => {
- if (narrow === previous) return;
- const docked = Array.from(
- root()?.querySelectorAll<HTMLElement>(
- ':scope > [data-resize-zone] > [data-resize-panel]'
- ) ?? []
- ).find((panel) => panel.querySelector('[data-view-shell-aside]'));
- const retain =
- narrow &&
- !asideRequired() &&
- !!docked &&
- !docked.classList.contains('hidden');
- animateSidebar(
- () => {
- if (!narrow) setAsideHost('docked');
- else setAsideHost(retain ? 'closing' : 'overlay');
- },
- () => {
- if (narrow) setAsideHost('overlay');
- }
- );
- },
- { defer: true }
- )
+ on(measuredLayoutBreakpoint, (narrow, previous) => {
+ if (narrow === undefined || narrow === previous) return;
+ // The first measurable layout is not a user-initiated resize.
+ if (previous === undefined) {
+ setAsideHost(narrow ? 'overlay' : 'docked');
+ return;
+ }
+ const docked = Array.from(
+ root()?.querySelectorAll<HTMLElement>(
+ ':scope > [data-resize-zone] > [data-resize-panel]'
+ ) ?? []
+ ).find((panel) => panel.querySelector('[data-view-shell-aside]'));
+ const retain =
+ narrow &&
+ !asideRequired() &&
+ !!docked &&
+ !docked.classList.contains('hidden');
+ animateSidebar(
+ () => {
+ if (!narrow) setAsideHost('docked');
+ else setAsideHost(retain ? 'closing' : 'overlay');
+ },
+ () => {
+ if (narrow) setAsideHost('overlay');
+ }
+ );
+ })
);
// Pin changes animate the current docked host, but cannot interrupt its exit.
createComputed(
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index c36a162f50..ef2654f601 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -655,9 +655,11 @@ movement must not keep resizing the removed split. Arrow keys still resize
immediately, with Shift selecting the larger step.
A view's narrow/wide layout reads its width when it mounts, then applies later
-split or window resizes on the next animation frame. Open a channel beside Home,
-drag the split gutter back and forth across the narrow breakpoint, and resize
-the window: the console should show no `ResizeObserver loop completed with
+split or window resizes on the next animation frame. Opening Home in either a
+wide or narrow split must settle immediately, without sliding or growing its
+content from zero width. Later split resizes still animate sidebar closure.
+Open a channel beside Home, drag the split gutter across the narrow breakpoint,
+and resize the window: the console should show no `ResizeObserver loop completed with
undelivered notifications` errors, and the sidebar should switch between docked
and overlay as the split crosses the breakpoint. Drive and other `virtua` lists
can still report it from the virtualizer's own observer.