дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
Dragging the Git Log scrollbar through a long history stuttered and showed blank rows: the native scrollbar scrolls asynchronously in WebKit, so the virtual list rendered rows a frame or more after the new offset was painted. The list now uses a scrollbar drawn in the DOM (`Scrollbar` in `src/ui`) that sets the offset from pointer events and notifies scroll listeners at once, so the virtualizer renders the matching rows before the next paint. Rows are keyed by slot so a large jump updates the mounted rows instead of rebuilding them, overscan is lowered, and rows rendered mid-scroll draw their graph without edge hit targets, which come back once scrolling stops. Adds a `gitLogScrollbar` perf scenario with budgets.
47 рядки
1.8 KiB
TypeScript
47 рядки
1.8 KiB
TypeScript
import { act, render } from "@testing-library/react";
|
|
import { useRef } from "react";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { Scrollbar } from "./Scrollbar";
|
|
|
|
function Harness({ onScroll }: { onScroll: (top: number) => void }) {
|
|
const ref = useRef<HTMLDivElement>(null);
|
|
return (
|
|
<div style={{ position: "relative" }}>
|
|
<Scrollbar target={ref} contentHeight={1000} />
|
|
<div ref={ref} data-testid="scroller" onScroll={(e) => onScroll(e.currentTarget.scrollTop)} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
describe("Scrollbar", () => {
|
|
it("notifies scroll listeners synchronously while the thumb is dragged", () => {
|
|
const onScroll = vi.fn();
|
|
const { getByTestId, container } = render(<Harness onScroll={onScroll} />);
|
|
const scroller = getByTestId("scroller");
|
|
let top = 0;
|
|
Object.defineProperties(scroller, {
|
|
clientHeight: { value: 100 },
|
|
scrollHeight: { value: 1000 },
|
|
scrollTop: { get: () => top, set: (v: number) => (top = v) },
|
|
});
|
|
scroller.scrollTo = ((options: ScrollToOptions) => {
|
|
top = Math.max(0, Math.min(900, options.top ?? top));
|
|
}) as typeof scroller.scrollTo;
|
|
act(() => {
|
|
scroller.dispatchEvent(new Event("scroll"));
|
|
});
|
|
onScroll.mockClear();
|
|
|
|
const track = container.querySelector<HTMLElement>("[aria-hidden]")!;
|
|
const thumb = track.firstElementChild as HTMLElement;
|
|
track.setPointerCapture = () => {};
|
|
thumb.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, button: 0, clientY: 10 }));
|
|
track.dispatchEvent(new PointerEvent("pointermove", { bubbles: true, clientY: 46 }));
|
|
|
|
// A 32px thumb travels 68px of the track for 900px of content: 36px ≈ 476px.
|
|
expect(top).toBeCloseTo((36 / 68) * 900);
|
|
expect(onScroll).toHaveBeenCalledTimes(1);
|
|
expect(onScroll).toHaveBeenLastCalledWith(top);
|
|
});
|
|
});
|