Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(sidebar): scroll to the issue when Show in sidebar opens its project (#11466)
pseudoyu8c9f4095579c
diff --git a/packages/views/layout/panel-nav.test.tsx b/packages/views/layout/panel-nav.test.tsxindex 0c7a601f44..f57ddf8529 100644--- a/packages/views/layout/panel-nav.test.tsx+++ b/packages/views/layout/panel-nav.test.tsx@@ -1,7 +1,7 @@import { afterEach, describe, expect, it, vi } from "vitest";-import { render, screen, waitFor } from "@testing-library/react";+import { act, render, screen, waitFor } from "@testing-library/react";import { DEFAULT_APPEARANCE, useAppearanceStore } from "@multica/core/appearance";-import { PanelBody, PanelDisclosure, PanelScrollFadeContext } from "./panel-nav";+import { PanelBody, PanelDisclosure, PanelScrollFadeContext, usePanelDisclosureSettled } from "./panel-nav";// jsdom drops `mask-image`, so the fade stands in as a style it keeps.vi.mock("@multica/ui/hooks/use-scroll-fade", () => ({@@ -97,4 +97,53 @@ describe("PanelDisclosure", () => {);expect(screen.queryByText("reduced body")).toBeNull();});++ describe("usePanelDisclosureSettled", () => {+ function Probe() {+ return <span>{usePanelDisclosureSettled() ? "settled" : "opening"}</span>;+ }+ function Nested({ outer, inner }: { outer: boolean; inner: boolean }) {+ return (+ <PanelDisclosure open={outer}>+ <PanelDisclosure open={inner}>+ <Probe />+ </PanelDisclosure>+ </PanelDisclosure>+ );+ }++ it("is settled from the start in a section that mounts open", () => {+ render(<Nested outer inner />);+ expect(screen.getByText("settled")).toBeInTheDocument();+ });++ it.each([+ { name: "its own section", from: { outer: true, inner: false } },+ { name: "the section around it", from: { outer: false, inner: true } },+ { name: "both", from: { outer: false, inner: false } },+ ])("waits for $name to finish opening", async ({ from }) => {+ const { rerender } = render(<Nested {...from} />);+ rerender(<Nested outer inner />);+ expect(screen.getByText("opening")).toBeInTheDocument();+ expect(await screen.findByText("settled")).toBeInTheDocument();+ });++ it("waits again when reopened before the close finishes", async () => {+ const { rerender } = render(<Nested outer inner />);+ rerender(<Nested outer inner={false} />);+ rerender(<Nested outer inner />);+ expect(screen.getByText("opening")).toBeInTheDocument();+ expect(await screen.findByText("settled")).toBeInTheDocument();+ });++ it("is settled in the same frame under reduced motion, and stays so when motion returns", () => {+ useAppearanceStore.setState({ ...DEFAULT_APPEARANCE, reduceMotion: true });+ const { rerender } = render(<Nested outer={false} inner={false} />);+ rerender(<Nested outer inner />);+ expect(screen.getByText("settled")).toBeInTheDocument();++ act(() => useAppearanceStore.setState({ ...DEFAULT_APPEARANCE }));+ expect(screen.getByText("settled")).toBeInTheDocument();+ });+ });});diff --git a/packages/views/layout/panel-nav.tsx b/packages/views/layout/panel-nav.tsxindex c514e83b5b..2bbc5199da 100644--- a/packages/views/layout/panel-nav.tsx+++ b/packages/views/layout/panel-nav.tsx@@ -1,6 +1,6 @@"use client";-import { createContext, useContext, useId, useRef, type RefObject } from "react";+import { createContext, useContext, useId, useRef, useState, type RefObject } from "react";import { AnimatePresence, motion, useIsPresent } from "motion/react";import { useReducedMotion } from "@multica/core/appearance";import { ChevronDown } from "@multica/ui/icons";@@ -105,13 +105,25 @@ export function PanelBody({);}+const PanelDisclosureSettledContext = createContext(true);++/**+ * False while an enclosing `PanelDisclosure` is still opening, when the rows+ * inside are not at their final position and scrolling to one would miss it.+ */+export function usePanelDisclosureSettled() {+ return useContext(PanelDisclosureSettledContext);+}+function PanelDisclosureInner({id,className,+ onOpened,children,}: {id?: string;className?: string;+ onOpened: () => void;children: React.ReactNode;}) {const isPresent = useIsPresent();@@ -134,6 +146,9 @@ function PanelDisclosureInner({overflow: "hidden",transition: { duration: UI_MOTION_DURATION.fast, ease: UI_EASE_OUT },}}+ onAnimationComplete={() => {+ if (isPresent) onOpened();+ }}className={cn(!isPresent && "pointer-events-none", className)}>{children}@@ -158,6 +173,9 @@ export function PanelDisclosure({children: React.ReactNode;}) {const reduceMotion = useReducedMotion();+ const parentSettled = usePanelDisclosureSettled();+ const [settled, setSettled] = useState(open);+ if (settled !== open && (!open || reduceMotion)) setSettled(open);if (reduceMotion) {return open ? (<div id={id} className={className}>@@ -166,13 +184,15 @@ export function PanelDisclosure({) : null;}return (- <AnimatePresence initial={false}>- {open && (- <PanelDisclosureInner key="disclosure" id={id} className={className}>- {children}- </PanelDisclosureInner>- )}- </AnimatePresence>+ <PanelDisclosureSettledContext.Provider value={parentSettled && settled}>+ <AnimatePresence initial={false}>+ {open && (+ <PanelDisclosureInner key="disclosure" id={id} className={className} onOpened={() => setSettled(true)}>+ {children}+ </PanelDisclosureInner>+ )}+ </AnimatePresence>+ </PanelDisclosureSettledContext.Provider>);}diff --git a/packages/views/layout/panels/sidebar-tree.tsx b/packages/views/layout/panels/sidebar-tree.tsxindex e219d70de6..b958826102 100644--- a/packages/views/layout/panels/sidebar-tree.tsx+++ b/packages/views/layout/panels/sidebar-tree.tsx@@ -28,7 +28,7 @@ import { type IssueAgentState, useIssueAgentState } from "../../issues/surface/uimport { useStatusLabel } from "../../issues/utils/status-label";import { DeferredPopup } from "../../common/deferred-popup";import { useT, useTimeAgo } from "../../i18n";-import { PANEL_ROW_CLASS, panelRowAnchor, panelRowStateClass } from "../panel-nav";+import { PANEL_ROW_CLASS, panelRowAnchor, panelRowStateClass, usePanelDisclosureSettled } from "../panel-nav";/** A working agent's issue title: dimmer at rest and a wider highlight than* the default shimmer, so the sweep reads at sidebar size. */@@ -362,6 +362,7 @@ export function SidebarIssueList({const locating = useSidebarTreeStore((s) => !!activeIssueId && s.locate?.source === source && s.locate.issueId === activeIssueId,);+ const settled = usePanelDisclosureSettled();const onKeyDown = (event: React.KeyboardEvent) => {if (event.key !== "ArrowLeft") return;@@ -410,7 +411,7 @@ export function SidebarIssueList({issue={issue}href={p.issueDetail(issueRouteRef(issue))}active={issue.id === activeIssueId}- locating={locating && issue.id === activeIssueId}+ locating={locating && settled && issue.id === activeIssueId}statusColor={statusCatalog.colorOf(issue.status)}statusIcon={statusCatalog.iconOf(issue.status)}statusLabel={statusLabel(issue.status)}diff --git a/packages/views/layout/panels/work-panel.test.tsx b/packages/views/layout/panels/work-panel.test.tsxindex caeeaeeb74..ec1fd32a00 100644--- a/packages/views/layout/panels/work-panel.test.tsx+++ b/packages/views/layout/panels/work-panel.test.tsx@@ -788,6 +788,28 @@ describe("WorkPanel and the open issue's project", () => {expect(litIssueRows()).toEqual([within(list).getByRole("link", { name: ISSUE.title })]);await waitFor(() => expect(useSidebarTreeStore.getState().locate).toBeNull());});++ it("scrolls to the issue only once its project has finished opening", async () => {+ const qc = renderPanel(`/acme/issues/${ISSUE.id}`, [], [PROJECT]);+ await openInProject(qc);+ await screen.findByRole("link", { name: ISSUE.title });++ const heights: string[] = [];+ const original = Element.prototype.scrollIntoView;+ Element.prototype.scrollIntoView = function (this: Element) {+ const list = this.closest("[data-sidebar-list]");+ if (list) heights.push(list.parentElement!.style.height);+ };+ try {+ act(() => {+ useSidebarTreeStore.getState().requestLocate({ issueId: ISSUE.id, source: PROJECT_SOURCE });+ });+ await waitFor(() => expect(useSidebarTreeStore.getState().locate).toBeNull());+ expect(heights).toEqual(["auto"]);+ } finally {+ Element.prototype.scrollIntoView = original;+ }+ });});describe("KeptRowsRelease Inbox Zero undo", () => {