Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(views): restore the board's horizontal scroll across tab switches (#10720)

rawlencee7a41d8b05df
diff --git a/apps/desktop/src/renderer/src/platform/tab-coordinator.test.ts b/apps/desktop/src/renderer/src/platform/tab-coordinator.test.ts
index 416be546e9..c6788675ba 100644
--- a/apps/desktop/src/renderer/src/platform/tab-coordinator.test.ts
+++ b/apps/desktop/src/renderer/src/platform/tab-coordinator.test.ts
@@ -63,6 +63,30 @@ describe("tab-coordinator external scroll sources", () => {
registerActiveHostElement(null);
});
+ it("captures a scroll root scrolled only sideways with its horizontal offset", () => {
+ const tabId = seedActiveTab("/acme/issues", "Issues");
+ const host = document.createElement("div");
+ const board = document.createElement("div");
+ board.setAttribute("data-tab-scroll-root", "board");
+ board.scrollLeft = 640;
+ Object.defineProperty(board, "scrollHeight", { value: 800, configurable: true });
+ host.appendChild(board);
+ registerActiveHostElement(host);
+
+ useTabStore.getState().openTab("/acme/inbox", "Inbox", { activate: true });
+
+ const outgoing = useTabStore
+ .getState()
+ .byWorkspace.acme.tabs.find((t) => t.id === tabId)!;
+ expect(outgoing.memento.scroll["/acme/issues::board"]).toEqual({
+ top: 0,
+ height: 800,
+ left: 640,
+ });
+
+ registerActiveHostElement(null);
+ });
+
it("writes external-source entries even at top:0 so a contentKey change clears stale offsets", () => {
const tabId = seedActiveTab("/acme/attachments/abc/preview", "Report");
const adapter = createScrollRestorationAdapter(tabId);
diff --git a/apps/desktop/src/renderer/src/platform/tab-coordinator.ts b/apps/desktop/src/renderer/src/platform/tab-coordinator.ts
index afe07e16b8..39a1fed0d5 100644
--- a/apps/desktop/src/renderer/src/platform/tab-coordinator.ts
+++ b/apps/desktop/src/renderer/src/platform/tab-coordinator.ts
@@ -175,7 +175,7 @@ function reconcile(): void {
*
* Plain scroll containers self-mark with `data-tab-scroll-root` (the
* attribute value is the container key, "main" when bare). Containers sitting
- * at 0 are simply absent from the result — the store's per-route REPLACE
+ * at 0 on both axes are simply absent from the result — the store's per-route REPLACE
* semantics turn that absence into "clear the stale offset".
*
* External sources (sandboxed iframe documents) are merged in for the
@@ -193,9 +193,13 @@ function captureScrollEntries(
"[data-tab-scroll-root]",
);
els.forEach((el) => {
- if (el.scrollTop <= 0) return;
+ const { scrollTop: top, scrollLeft: left } = el;
+ if (top <= 0 && left <= 0) return;
const key = el.getAttribute("data-tab-scroll-root") || "main";
- entries[key] = { top: el.scrollTop, height: el.scrollHeight };
+ entries[key] =
+ left > 0
+ ? { top, height: el.scrollHeight, left }
+ : { top, height: el.scrollHeight };
});
}
if (outgoingTabId) {
diff --git a/apps/desktop/src/renderer/src/stores/tab-store.test.ts b/apps/desktop/src/renderer/src/stores/tab-store.test.ts
index ce7bc508ee..aa101f4b17 100644
--- a/apps/desktop/src/renderer/src/stores/tab-store.test.ts
+++ b/apps/desktop/src/renderer/src/stores/tab-store.test.ts
@@ -1051,6 +1051,25 @@ describe("commitScrollMemento", () => {
expect(useTabStore.getState().byWorkspace.acme).toBe(before);
});
+ it("writes when only the horizontal offset changed", () => {
+ const store = useTabStore.getState();
+ store.switchWorkspace("acme");
+ const tabId = useTabStore.getState().byWorkspace.acme.tabs[0].id;
+ store.commitScrollMemento(tabId, "/acme/issues", {
+ board: { top: 0, height: 800, left: 300 },
+ });
+
+ store.commitScrollMemento(tabId, "/acme/issues", {
+ board: { top: 0, height: 800, left: 900 },
+ });
+
+ expect(
+ useTabStore.getState().byWorkspace.acme.tabs[0].memento.scroll[
+ "/acme/issues::board"
+ ],
+ ).toEqual({ top: 0, height: 800, left: 900 });
+ });
+
it("preserves view-state entries across a scroll REPLACE", () => {
const store = useTabStore.getState();
store.switchWorkspace("acme");
diff --git a/apps/desktop/src/renderer/src/stores/tab-store.ts b/apps/desktop/src/renderer/src/stores/tab-store.ts
index 7b3c549871..8379f864a4 100644
--- a/apps/desktop/src/renderer/src/stores/tab-store.ts
+++ b/apps/desktop/src/renderer/src/stores/tab-store.ts
@@ -27,6 +27,8 @@ import { isIssueUuid } from "@multica/core/issues/canonical-id";
export interface ScrollMementoEntry {
top: number;
height: number;
+ /** Horizontal offset, present only when > 0. */
+ left?: number;
contentKey?: string;
}
@@ -1246,6 +1248,7 @@ export const useTabStore = create<TabStore>()(
prev !== undefined &&
prev.top === next.top &&
prev.height === next.height &&
+ prev.left === next.left &&
prev.contentKey === next.contentKey
);
});
diff --git a/apps/web/platform/scroll-restoration.test.tsx b/apps/web/platform/scroll-restoration.test.tsx
index c5e1b471dc..89be24ae21 100644
--- a/apps/web/platform/scroll-restoration.test.tsx
+++ b/apps/web/platform/scroll-restoration.test.tsx
@@ -1,7 +1,10 @@
// @vitest-environment jsdom
import { describe, expect, it } from "vitest";
import { render, screen } from "@testing-library/react";
-import { useRestoredScrollOffset } from "@multica/views/platform";
+import {
+ useRestoredScrollEntry,
+ useRestoredScrollOffset,
+} from "@multica/views/platform";
import { WebScrollRestorationProvider } from "./scroll-restoration";
function ScrollProbe({ containerKey }: { containerKey: string }) {
@@ -9,6 +12,13 @@ function ScrollProbe({ containerKey }: { containerKey: string }) {
return <output data-testid="restored">{restored ?? "none"}</output>;
}
+function EntryProbe({ containerKey }: { containerKey: string }) {
+ const entry = useRestoredScrollEntry(containerKey);
+ return (
+ <output data-testid="entry">{entry ? JSON.stringify(entry) : "none"}</output>
+ );
+}
+
/** Dispatch a real scroll event from a marked container element. */
function scrollContainer(el: HTMLElement, top: number) {
Object.defineProperty(el, "scrollTop", { configurable: true, value: top });
@@ -88,6 +98,26 @@ describe("WebScrollRestorationProvider", () => {
expect(screen.getByTestId("restored").textContent).toBe("480");
});
+ it("keeps a container scrolled only sideways", () => {
+ const view = render(
+ <WebScrollRestorationProvider>
+ <div data-tab-scroll-root="board" data-testid="container" />
+ </WebScrollRestorationProvider>,
+ );
+ const container = screen.getByTestId("container");
+ container.scrollLeft = 640;
+ scrollContainer(container, 0);
+
+ view.rerender(
+ <WebScrollRestorationProvider>
+ <EntryProbe containerKey="board" />
+ </WebScrollRestorationProvider>,
+ );
+ expect(screen.getByTestId("entry").textContent).toBe(
+ JSON.stringify({ top: 0, height: 2000, left: 640 }),
+ );
+ });
+
it("ignores scrolls from unmarked elements", () => {
render(
<WebScrollRestorationProvider>
diff --git a/apps/web/platform/scroll-restoration.tsx b/apps/web/platform/scroll-restoration.tsx
index da1d19ec23..a60cbd506b 100644
--- a/apps/web/platform/scroll-restoration.tsx
+++ b/apps/web/platform/scroll-restoration.tsx
@@ -4,6 +4,7 @@ import { useEffect, useMemo, type ReactNode } from "react";
import {
ScrollRestorationProvider,
type ScrollRestorationAdapter,
+ type ScrollRestorationEntry,
} from "@multica/views/platform";
/**
@@ -27,7 +28,7 @@ import {
* tabs are real tabs), reset on full reload where the browser's own
* restoration takes over.
*/
-const savedOffsets = new Map<string, { top: number; height: number }>();
+const savedOffsets = new Map<string, ScrollRestorationEntry>();
/**
* Generic view-state entries (the desktop memento's second cargo — e.g.
@@ -70,12 +71,18 @@ export function WebScrollRestorationProvider({
if (performance.now() < suppressed) return;
suppressedUntil.delete(key);
}
- if (el.scrollTop <= 0) {
- // Back at the top is the default state — a stale offset would
+ const { scrollTop: top, scrollLeft: left } = el;
+ if (top <= 0 && left <= 0) {
+ // Back at the origin is the default state — a stale offset would
// otherwise resurrect on the next visit.
savedOffsets.delete(key);
} else {
- savedOffsets.set(key, { top: el.scrollTop, height: el.scrollHeight });
+ savedOffsets.set(
+ key,
+ left > 0
+ ? { top, height: el.scrollHeight, left }
+ : { top, height: el.scrollHeight },
+ );
}
};
// Scroll events don't bubble, but they do propagate on the capture
diff --git a/packages/views/issues/components/board-view-project-grouping.test.tsx b/packages/views/issues/components/board-view-project-grouping.test.tsx
index d08cd6deea..2d73361834 100644
--- a/packages/views/issues/components/board-view-project-grouping.test.tsx
+++ b/packages/views/issues/components/board-view-project-grouping.test.tsx
@@ -17,6 +17,10 @@ import { renderWithI18n } from "../../test/i18n";
import { IssueContextMenuProvider } from "../actions/issue-actions-context-menu";
import type { IssueGroupBranches } from "../surface/use-issue-group-branches";
import { BoardView } from "./board-view";
+import {
+ ScrollRestorationProvider,
+ type ScrollRestorationAdapter,
+} from "../../platform";
vi.mock("@multica/core/hooks", () => ({ useWorkspaceId: () => "ws-1" }));
@@ -196,9 +200,11 @@ describe("Board grouped by project", () => {
function render({
descriptors = [NO_PROJECT_DESCRIPTOR, ...PROJECT_DESCRIPTORS],
issues = ISSUES,
+ scrollAdapter = { get: () => undefined },
}: {
descriptors?: IssueGroupBranches["descriptors"];
issues?: Issue[];
+ scrollAdapter?: ScrollRestorationAdapter;
} = {}) {
const store = getIssueSurfaceViewStore(
`board-project-${Math.floor(Math.random() * 1e9)}`,
@@ -212,6 +218,7 @@ describe("Board grouped by project", () => {
renderWithI18n(
<QueryClientProvider client={queryClient}>
<ViewStoreProvider store={store}>
+ <ScrollRestorationProvider adapter={scrollAdapter}>
<IssueContextMenuProvider>
<BoardView
issues={issues}
@@ -223,6 +230,7 @@ describe("Board grouped by project", () => {
groupBranches={makeGroupBranches(descriptors, issues)}
/>
</IssueContextMenuProvider>
+ </ScrollRestorationProvider>
</ViewStoreProvider>
</QueryClientProvider>,
);
@@ -289,4 +297,19 @@ describe("Board grouped by project", () => {
expect(acmeColumn.textContent).toContain("MUL-acme");
expect(acmeColumn.textContent).not.toContain("MUL-loose");
});
+
+ it("brings the column strip back to where it was scrolled sideways", () => {
+ render({
+ scrollAdapter: {
+ get: (key) =>
+ key === "board" ? { top: 0, height: 600, left: 480 } : undefined,
+ },
+ });
+
+ const strip = document.querySelector<HTMLElement>("[data-board-scroller]")!;
+ // Marked so the tab coordinator captures it on the way out …
+ expect(strip.getAttribute("data-tab-scroll-root")).toBe("board");
+ // … and given the saved offset back when it mounts again.
+ expect(strip.scrollLeft).toBe(480);
+ });
});
diff --git a/packages/views/issues/components/board-view.tsx b/packages/views/issues/components/board-view.tsx
index 47877f5cc2..1b8d56cab3 100644
--- a/packages/views/issues/components/board-view.tsx
+++ b/packages/views/issues/components/board-view.tsx
@@ -59,6 +59,7 @@ import type {
import { useDragSettle } from "./use-drag-settle";
import { useIssuePeekActions } from "../surface/peek-context";
import { useBoardDragPan } from "./use-board-drag-pan";
+import { useRestoredScrollRef } from "../../platform";
import { useT } from "../../i18n";
import {
type DragMoveUpdates,
@@ -588,6 +589,16 @@ function BoardViewImpl({
// #6700: drag empty board background with the left button to pan horizontally
// (Trello/Linear). Card drags start on `[data-board-card]` and are ignored.
const pan = useBoardDragPan<HTMLDivElement>();
+ // Tab-session scroll restoration (MUL-4741) for the horizontal column
+ // strip; each column's own vertical offset is restored by BoardColumn.
+ const restoreScrollRef = useRestoredScrollRef("board");
+ const attachScroller = useCallback(
+ (el: HTMLDivElement | null) => {
+ pan.ref.current = el;
+ restoreScrollRef(el);
+ },
+ [pan.ref, restoreScrollRef],
+ );
const handleDragStart = useCallback(
(event: DragStartEvent) => {
@@ -836,13 +847,14 @@ function BoardViewImpl({
onDragCancel={handleDragCancel}
>
<div
- ref={pan.ref}
+ ref={attachScroller}
onPointerDown={pan.onPointerDown}
onPointerMove={pan.onPointerMove}
onPointerUp={pan.onPointerUp}
onPointerCancel={pan.onPointerCancel}
onLostPointerCapture={pan.onLostPointerCapture}
data-board-scroller=""
+ data-tab-scroll-root="board"
className={cn(
"flex flex-1 min-h-0 gap-4 overflow-x-auto p-2",
// While a side peek is open, a trailing spacer as wide as the panel
diff --git a/packages/views/platform/scroll-restoration.test.tsx b/packages/views/platform/scroll-restoration.test.tsx
index 1605897a04..915db0a0ae 100644
--- a/packages/views/platform/scroll-restoration.test.tsx
+++ b/packages/views/platform/scroll-restoration.test.tsx
@@ -1,9 +1,11 @@
+import type { ReactNode } from "react";
import { describe, expect, it } from "vitest";
import { renderHook } from "@testing-library/react";
import {
ScrollRestorationProvider,
useRestoredScrollEntry,
useRestoredScrollOffset,
+ useRestoredScrollRef,
useScrollRestorationAdapter,
type ScrollRestorationAdapter,
} from "./scroll-restoration";
@@ -34,6 +36,26 @@ describe("scroll-restoration public surface", () => {
expect(result.current).toBe(123);
});
+ it("useRestoredScrollRef restores both axes; a sideways-only entry has no vertical offset", () => {
+ const adapter = makeAdapter(() => ({ top: 0, height: 800, left: 640 }));
+ const wrapper = ({ children }: { children: ReactNode }) => (
+ <ScrollRestorationProvider adapter={adapter}>
+ {children}
+ </ScrollRestorationProvider>
+ );
+ const ref = renderHook(() => useRestoredScrollRef("board"), { wrapper });
+ const offset = renderHook(() => useRestoredScrollOffset("board"), {
+ wrapper,
+ });
+
+ const el = document.createElement("div");
+ ref.result.current(el);
+
+ expect(el.scrollLeft).toBe(640);
+ expect(el.scrollTop).toBe(0);
+ expect(offset.result.current).toBeUndefined();
+ });
+
it("all hooks return undefined without a provider (web no-op path)", () => {
const entry = renderHook(() => useRestoredScrollEntry("x"));
const offset = renderHook(() => useRestoredScrollOffset("x"));
diff --git a/packages/views/platform/scroll-restoration.tsx b/packages/views/platform/scroll-restoration.tsx
index b8edb85a09..849d37c900 100644
--- a/packages/views/platform/scroll-restoration.tsx
+++ b/packages/views/platform/scroll-restoration.tsx
@@ -36,10 +36,14 @@ import {
* so a re-upload to the same attachment id refuses to restore a stale offset.
* Plain containers leave it undefined and get identity comparison (undefined
* === undefined), so they are unaffected.
+ *
+ * `left` is the horizontal offset, present only when it is > 0 (e.g. the
+ * board's column strip scrolled sideways); an entry may then carry top 0.
*/
export interface ScrollRestorationEntry {
top: number;
height: number;
+ left?: number;
contentKey?: string;
}
@@ -126,19 +130,23 @@ export function useRestoredScrollEntry(
}
/**
- * The saved scroll offset for a container key on the current route, or
- * undefined. Read it once at mount (e.g. into a Virtuoso `initialScrollTop`)
- * — it reflects the state captured when this route was last left.
+ * The saved vertical scroll offset for a container key on the current route,
+ * or undefined when there is none (an entry saved only for its horizontal
+ * offset counts as none). Read it once at mount (e.g. into a Virtuoso
+ * `initialScrollTop`) — it reflects the state captured when this route was
+ * last left.
*/
export function useRestoredScrollOffset(containerKey: string): number | undefined {
- return useRestoredScrollEntry(containerKey)?.top;
+ const top = useRestoredScrollEntry(containerKey)?.top;
+ return top !== undefined && top > 0 ? top : undefined;
}
/**
* Ref callback for PLAIN (non-virtualized) scroll containers: assigns the
- * saved offset when the element attaches, which happens during commit —
- * before paint — so the first visible frame is already at the restored
- * position. Compose it with other refs via a merged callback.
+ * saved offsets (vertical and horizontal) when the element attaches, which
+ * happens during commit — before paint — so the first visible frame is
+ * already at the restored position. Compose it with other refs via a merged
+ * callback.
*/
export function useRestoredScrollRef(
containerKey: string,
@@ -148,8 +156,11 @@ export function useRestoredScrollRef(
(el: HTMLElement | null) => {
if (!el) return;
const saved = adapter?.get(containerKey);
- if (!saved || saved.top <= 0) return;
- el.scrollTop = saved.top;
+ if (!saved) return;
+ if (saved.top > 0) el.scrollTop = saved.top;
+ if (saved.left !== undefined && saved.left > 0) {
+ el.scrollLeft = saved.left;
+ }
},
[adapter, containerKey],
);