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): apply view shell resizes after observer delivery (#8702)

Eric Hayesf3121652f3c6
diff --git a/apps/web/src/components/view-shell/ViewShell.test.tsx b/apps/web/src/components/view-shell/ViewShell.test.tsx
index 515b44dfa3..67c55bf123 100644
--- a/apps/web/src/components/view-shell/ViewShell.test.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.test.tsx
@@ -35,6 +35,10 @@ vi.mock('@solid-primitives/resize-observer', () => ({
}),
}));
+vi.mock('./create-frame-width', () => ({
+ createFrameWidth: () => () => measurement.width(),
+}));
+
vi.mock('@ui', async () => ({
...(await import('../ui/utils/classname')),
...(await import('../ui/utils/press')),
diff --git a/apps/web/src/components/view-shell/ViewShell.tsx b/apps/web/src/components/view-shell/ViewShell.tsx
index 2b7d111ed8..c19ee29a70 100644
--- a/apps/web/src/components/view-shell/ViewShell.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.tsx
@@ -14,7 +14,6 @@ import SidebarIcon from '@icon/system/regular/sidebar-simple.svg';
import CloseIcon from '@icon/system/regular/x.svg';
import { createWritableMemo } from '@solid-primitives/memo';
import { mergeRefs } from '@solid-primitives/refs';
-import { createElementSize } from '@solid-primitives/resize-observer';
import { Button, cn } from '@ui';
import { CollapseTransition } from '@ui/components/CollapseTransition';
import { tourTarget } from '@ui/components/Tour';
@@ -35,6 +34,7 @@ import {
untrack,
useContext,
} from 'solid-js';
+import { createFrameWidth } from './create-frame-width';
import { createSidebarMotion } from './create-sidebar-motion';
import { VIEW_SHELL_TOUR } from './tour';
import {
@@ -202,7 +202,7 @@ function Root(props: ViewShellRootProps) {
const id = createUniqueId();
const [root, setRoot] = createSignal<HTMLDivElement>();
const animateSidebar = createSidebarMotion(root);
- const size = createElementSize(root);
+ const width = createFrameWidth(root);
const thresholds = (): BreakpointThresholds =>
local.breakpoints ?? DEFAULT_VIEW_SHELL_BREAKPOINT_THRESHOLDS;
@@ -246,7 +246,6 @@ function Root(props: ViewShellRootProps) {
};
const resizable = () => local.resizable ?? false;
- const width = () => size.width ?? undefined;
const breakpoints = createSizeBreakpoints(width, thresholds);
const atLayoutBreakpoint = () => {
diff --git a/apps/web/src/components/view-shell/create-frame-width.test.ts b/apps/web/src/components/view-shell/create-frame-width.test.ts
new file mode 100644
index 0000000000..0f6ec476ab
--- /dev/null
+++ b/apps/web/src/components/view-shell/create-frame-width.test.ts
@@ -0,0 +1,95 @@
+/** @vitest-environment jsdom */
+
+import { createRoot, createSignal } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { createFrameWidth } from './create-frame-width';
+
+const resize = vi.hoisted(() => ({
+ notify: (_size: unknown, _element: Element) => {},
+}));
+vi.mock('@solid-primitives/resize-observer', () => ({
+ createResizeObserver: (
+ _target: unknown,
+ callback: (size: unknown, element: Element) => void
+ ) => {
+ resize.notify = callback;
+ },
+}));
+
+const cleanups: Array<() => void> = [];
+
+beforeEach(() => {
+ vi.useFakeTimers({
+ toFake: ['requestAnimationFrame', 'cancelAnimationFrame'],
+ });
+});
+
+afterEach(() => {
+ for (const cleanup of cleanups.splice(0)) cleanup();
+ vi.useRealTimers();
+});
+
+function setup() {
+ let layoutWidth = 1000;
+ const element = document.createElement('div');
+ element.getBoundingClientRect = () => new DOMRect(0, 0, layoutWidth, 600);
+ const [target, setTarget] = createSignal<HTMLElement>();
+ const width = createRoot((dispose) => {
+ cleanups.push(dispose);
+ return createFrameWidth(target);
+ });
+ return {
+ width,
+ element,
+ mount: () => setTarget(element),
+ resizeTo(next: number) {
+ layoutWidth = next;
+ resize.notify({ width: next, height: 600 }, element);
+ },
+ };
+}
+
+describe('createFrameWidth', () => {
+ it('reads the width when the element mounts', () => {
+ const view = setup();
+ expect(view.width()).toBeUndefined();
+
+ view.mount();
+
+ expect(view.width()).toBe(1000);
+ });
+
+ it('applies observed widths in the next frame, not during delivery', () => {
+ const view = setup();
+ view.mount();
+
+ view.resizeTo(700);
+ expect(view.width()).toBe(1000);
+
+ vi.advanceTimersToNextFrame();
+ expect(view.width()).toBe(700);
+ });
+
+ it('coalesces several observations into the latest width', () => {
+ const view = setup();
+ view.mount();
+
+ view.resizeTo(900);
+ view.resizeTo(800);
+ view.resizeTo(650);
+ vi.advanceTimersToNextFrame();
+
+ expect(view.width()).toBe(650);
+ });
+
+ it('drops a pending frame when disposed', () => {
+ const view = setup();
+ view.mount();
+ view.resizeTo(500);
+
+ for (const cleanup of cleanups.splice(0)) cleanup();
+ vi.advanceTimersToNextFrame();
+
+ expect(view.width()).toBe(1000);
+ });
+});
diff --git a/apps/web/src/components/view-shell/create-frame-width.ts b/apps/web/src/components/view-shell/create-frame-width.ts
new file mode 100644
index 0000000000..16ddce4c23
--- /dev/null
+++ b/apps/web/src/components/view-shell/create-frame-width.ts
@@ -0,0 +1,40 @@
+import { createResizeObserver } from '@solid-primitives/resize-observer';
+import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js';
+
+/**
+ * Tracks an element's border-box width for layout decisions.
+ *
+ * The first width is read when the element mounts so the initial layout is
+ * right. Later observer-reported widths apply in the next animation frame:
+ * they switch breakpoints that resize observed descendants, and doing that
+ * during ResizeObserver delivery drops those descendants' notifications.
+ */
+export function createFrameWidth(
+ target: Accessor<HTMLElement | undefined>
+): Accessor<number | undefined> {
+ const [width, setWidth] = createSignal<number>();
+ let frame: number | undefined;
+
+ const cancelFrame = () => {
+ if (frame === undefined) return;
+ cancelAnimationFrame(frame);
+ frame = undefined;
+ };
+
+ createEffect(() => {
+ const element = target();
+ cancelFrame();
+ setWidth(element?.getBoundingClientRect().width);
+ });
+ createResizeObserver(target, (_, element) => {
+ if (!(element instanceof HTMLElement)) return;
+ cancelFrame();
+ frame = requestAnimationFrame(() => {
+ frame = undefined;
+ setWidth(element.getBoundingClientRect().width);
+ });
+ });
+ onCleanup(cancelFrame);
+
+ return width;
+}
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index fc57afd79d..06436f66d6 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -650,6 +650,14 @@ dragging at non-default zoom, and closing a split during a drag; later pointer
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
+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.
+
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,
with regular-weight labels and consistent icon spacing.