Skip to content

Your lightweight open-source personal agent.

fix(webui): preserve sidebar highlight easing during resize

Xubin Ren14f46d21fdaa
diff --git a/webui/src/App.tsx b/webui/src/App.tsx
index 9f73fbd57..a4f92c8f0 100644
--- a/webui/src/App.tsx
+++ b/webui/src/App.tsx
@@ -2603,9 +2603,10 @@ function Shell({
{showMainSidebar ? (
<aside
data-testid="host-sidebar-flow"
+ data-resizing={sidebarDragging || undefined}
id="main-sidebar"
className={cn(
- "relative z-20 hidden shrink-0 overflow-hidden lg:block",
+ "group/sidebar relative z-20 hidden shrink-0 overflow-hidden lg:block",
sidebarDragging ? "select-none" : "transition-[width] duration-300 ease-out motion-reduce:transition-none",
)}
style={{
diff --git a/webui/src/components/SidebarSelectionHighlight.tsx b/webui/src/components/SidebarSelectionHighlight.tsx
index 370408f77..aa740c431 100644
--- a/webui/src/components/SidebarSelectionHighlight.tsx
+++ b/webui/src/components/SidebarSelectionHighlight.tsx
@@ -15,8 +15,9 @@ interface SidebarSelectionHighlightProps extends HTMLAttributes<HTMLDivElement>
export const SIDEBAR_SELECTION_ITEM_CLASS =
"relative z-[1] transition-[color] duration-150 ease-out motion-reduce:transition-none";
+// During a drag, animate only the shared highlight, not its measured target as well.
export const SIDEBAR_SELECTION_ACTION_ITEM_CLASS =
- "relative z-[1] transition-[width,padding,color] [transition-duration:300ms,300ms,150ms] ease-out motion-reduce:transition-none";
+ "relative z-[1] transition-[width,padding,color] [transition-duration:300ms,300ms,150ms] ease-out group-data-[resizing=true]/sidebar:transition-none motion-reduce:transition-none";
export function SidebarSelectionHighlight({
targetRef,
@@ -44,6 +45,7 @@ export function SidebarSelectionHighlight({
}
let restoreTransitionFrame: number | null = null;
+ let positionFrame: number | null = null;
const position = () => {
const containerRect = container.getBoundingClientRect();
@@ -73,20 +75,34 @@ export function SidebarSelectionHighlight({
}
};
- position();
+ // Measure once per animation frame so React rerenders do not repeatedly
+ // retarget a transition before the browser has advanced its current frame.
+ const schedulePosition = () => {
+ if (positionFrame !== null) return;
+ positionFrame = window.requestAnimationFrame(() => {
+ positionFrame = null;
+ position();
+ });
+ };
+
+ if (!positionedRef.current) position();
+ else schedulePosition();
const resizeObserver =
- typeof ResizeObserver === "undefined" ? null : new ResizeObserver(position);
+ typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedulePosition);
resizeObserver?.observe(container);
resizeObserver?.observe(target);
- window.addEventListener("resize", position);
+ window.addEventListener("resize", schedulePosition);
return () => {
if (restoreTransitionFrame !== null) {
window.cancelAnimationFrame(restoreTransitionFrame);
}
+ if (positionFrame !== null) {
+ window.cancelAnimationFrame(positionFrame);
+ }
highlight?.style.removeProperty("transition-property");
resizeObserver?.disconnect();
- window.removeEventListener("resize", position);
+ window.removeEventListener("resize", schedulePosition);
};
});
diff --git a/webui/src/tests/app-layout.test.tsx b/webui/src/tests/app-layout.test.tsx
index 8a324f7f4..a253f7aba 100644
--- a/webui/src/tests/app-layout.test.tsx
+++ b/webui/src/tests/app-layout.test.tsx
@@ -1741,9 +1741,13 @@ describe("App layout", () => {
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
const handle = screen.getByRole("separator", { name: "Resize sidebar" });
const sidebar = screen.getByTestId("host-sidebar-flow");
+ expect(sidebar).toHaveClass("group/sidebar");
fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 272 });
+ expect(sidebar).toHaveAttribute("data-resizing", "true");
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 360 });
+ expect(sidebar).toHaveStyle({ width: "360px" });
fireEvent.pointerUp(handle, { pointerId: 1, clientX: 360 });
+ expect(sidebar).not.toHaveAttribute("data-resizing");
expect(sidebar).toHaveStyle({ width: "360px" });
expect(localStorage.getItem("nanobot-webui.sidebar.width")).toBe("360");
fireEvent.pointerDown(handle, { button: 0, pointerId: 2, clientX: 360 });
@@ -1765,6 +1769,43 @@ describe("App layout", () => {
expect(screen.getByTestId("host-sidebar-flow")).toHaveStyle({ width: "272px" });
});
+ it.each(["pointerUp", "pointerCancel", "lostPointerCapture"] as const)("keeps highlight easing while disabling navigation target lag until %s", async (finish) => {
+ mockSessions = [{
+ key: "websocket:resize-test", channel: "websocket", chatId: "resize-test",
+ createdAt: "2026-04-16T10:00:00Z", updatedAt: "2026-04-16T10:00:00Z",
+ title: "Resize test", preview: "",
+ }];
+ render(<App />);
+ await waitFor(() => expect(connectSpy).toHaveBeenCalled());
+ const sidebar = screen.getByTestId("host-sidebar-flow");
+ await within(sidebar).findByTestId("chats-selection-highlight");
+ const handle = within(sidebar).getByRole("separator", { name: "Resize sidebar" });
+ for (const label of ["Apps", "Skills", "Automations", "Channels"]) {
+ expect(within(sidebar).getByRole("button", { name: label })).toHaveClass(
+ "group-data-[resizing=true]/sidebar:transition-none",
+ );
+ }
+ for (const scope of ["actions", "chats"]) {
+ const highlight = within(sidebar).getByTestId(`${scope}-selection-highlight`);
+ expect(highlight).not.toHaveClass(
+ "group-data-[resizing=true]/sidebar:transition-none",
+ );
+ expect(highlight).toHaveClass(
+ "transition-[transform,width,height]",
+ "duration-300",
+ "ease-out",
+ "motion-reduce:transition-none",
+ );
+ }
+ fireEvent.pointerDown(handle, { button: 0, pointerId: 1, clientX: 272 });
+ fireEvent.pointerMove(handle, { pointerId: 1, clientX: 400 });
+ expect(sidebar).toHaveAttribute("data-resizing", "true");
+ expect(sidebar).toHaveStyle({ width: "400px" });
+ fireEvent[finish](handle, { pointerId: 1, clientX: 400 });
+ expect(sidebar).not.toHaveAttribute("data-resizing");
+ expect(sidebar).toHaveClass("transition-[width]");
+ });
+
it("uses the shared sidebar controls and rail on the native host", async () => {
mockSessions = [
{
diff --git a/webui/src/tests/sidebar-selection-highlight.test.tsx b/webui/src/tests/sidebar-selection-highlight.test.tsx
new file mode 100644
index 000000000..fdcf19fb4
--- /dev/null
+++ b/webui/src/tests/sidebar-selection-highlight.test.tsx
@@ -0,0 +1,87 @@
+import { useRef } from "react";
+import { act, cleanup, render, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { SidebarSelectionHighlight } from "@/components/SidebarSelectionHighlight";
+
+afterEach(() => {
+ cleanup();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+});
+
+function Harness({ activeId, targetByRef }: { activeId: string | null; targetByRef: boolean }) {
+ const target = useRef<HTMLButtonElement>(null);
+ return <SidebarSelectionHighlight activeId={activeId} scope="test" data-testid="highlight-container"
+ targetRef={targetByRef ? target : undefined}
+ targetSelector={targetByRef ? undefined : "[aria-current=page]"}>
+ <button ref={activeId === "first" ? target : undefined} aria-current={activeId === "first" ? "page" : undefined}>First</button>
+ <button ref={activeId === "second" ? target : undefined} aria-current={activeId === "second" ? "page" : undefined}>Second</button>
+ </SidebarSelectionHighlight>;
+}
+
+describe("sidebar selection highlight geometry", () => {
+ it.each([true, false])("updates the animated width as its target resizes (target by ref: %s)", (targetByRef) => {
+ let width = 272;
+ let frameId = 0;
+ const frames = new Map<number, FrameRequestCallback>();
+ vi.spyOn(window, "requestAnimationFrame").mockImplementation((callback) => {
+ frames.set(++frameId, callback);
+ return frameId;
+ });
+ vi.spyOn(window, "cancelAnimationFrame").mockImplementation((id) => {
+ frames.delete(id);
+ });
+ const paint = () => act(() => {
+ const callbacks = [...frames.values()];
+ frames.clear();
+ callbacks.forEach((callback) => callback(performance.now()));
+ });
+ const resizes: Array<() => void> = [];
+ vi.stubGlobal("ResizeObserver", class {
+ constructor(callback: () => void) { resizes.push(callback); }
+ observe() {}
+ disconnect() {}
+ });
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (this: HTMLElement) {
+ const container = this.dataset.testid === "highlight-container";
+ const second = this.textContent === "Second";
+ const inset = container ? 0 : second ? 24 : 8;
+ const x = 100 + inset;
+ const y = container ? 20 : second ? 100 : 60;
+ const w = container ? width : width - inset - 8;
+ return { x, y, left: x, top: y, right: x + w, bottom: y + 32, width: w, height: 32, toJSON() {} };
+ });
+ const { rerender } = render(<Harness activeId="first" targetByRef={targetByRef} />);
+ const highlight = screen.getByTestId("test-selection-highlight");
+ expect(highlight).toHaveStyle({ width: "256px", height: "32px", transform: "translate3d(8px, 40px, 0)" });
+ paint();
+
+ // After initial placement, every observer update changes the animation's
+ // destination rather than waiting for a pointer-up or resize-end event.
+ rerender(<Harness activeId="first" targetByRef={targetByRef} />);
+ width = 300;
+ act(() => resizes.at(-1)?.());
+ width = 420;
+ act(() => resizes.at(-1)?.());
+ expect(frames.size).toBe(1);
+ expect(highlight).toHaveStyle({ width: "256px" });
+ paint();
+ expect(highlight).toHaveStyle({ width: "404px" });
+ expect(highlight.style.transitionProperty).not.toBe("none");
+ width = 320;
+ act(() => resizes.at(-1)?.());
+ paint();
+ expect(highlight).toHaveStyle({ width: "304px" });
+ expect(highlight.style.transitionProperty).not.toBe("none");
+ rerender(<Harness activeId="second" targetByRef={targetByRef} />);
+ paint();
+ expect(highlight).toHaveStyle({ width: "288px", transform: "translate3d(24px, 80px, 0)" });
+ expect(highlight.style.transitionProperty).not.toBe("none");
+ act(() => resizes.at(-1)?.());
+ expect(frames.size).toBe(1);
+ rerender(<Harness activeId={null} targetByRef={targetByRef} />);
+ expect(frames.size).toBe(0);
+ expect(highlight).toHaveStyle({ opacity: "0" });
+ });
+});