Prevent collector snapshot rerender stalls

Memoize the collector content across unrelated app snapshots and release collapsed child rows from the DOM after their closing animation. Draw the idle speed sparkline as a pixel-aligned one-physical-pixel stroke so its thickness remains uniform across display scales.
This commit is contained in:
Sucukdeluxe
2026-08-26 14:09:01 +02:00
parent 14525fa4c3
commit da4c2fb069
5 changed files with 84 additions and 16 deletions
+15 -4
View File
@@ -14,6 +14,7 @@ import {
import {
CollectorContent,
CollectorInputDialog,
MemoizedCollectorContent,
CollectorSidebar,
CollectorToolbar,
CollectorView,
@@ -323,10 +324,20 @@ describe("CollectorView", () => {
expect(html).not.toContain("SBS14HD.part01.rar");
});
it("keeps the animated disclosure frame mounted for compact packages", () => {
const html = renderToStaticMarkup(<CollectorContent actions={createActions()} model={buildCollectorWorkspaceViewModel(packages, "all", "", false, [], ["package-sbs"], "", true)} />);
expect(html).toContain("collector-package-items-frame is-collapsed is-animated");
expect(html).toContain("SBS14HD.part01.rar");
it("removes collapsed child rows from the DOM even when animations are enabled", () => {
const html = renderToStaticMarkup(<CollectorContent actions={createActions()} model={buildCollectorWorkspaceViewModel([packages[0]], "all", "", false, [], ["package-sbs"], "", true)} />);
expect(html).not.toContain("collector-package-items-frame");
expect(html).not.toContain("SBS14HD.part01.rar");
});
it("reuses the collector content when app snapshots keep the same collector model", () => {
const model = buildCollectorWorkspaceViewModel(packages, "all", "", false, [], [], "", true);
const compare = (MemoizedCollectorContent as unknown as {
compare: (previous: { model: typeof model; actions: CollectorViewActions }, next: { model: typeof model; actions: CollectorViewActions }) => boolean;
}).compare;
expect(compare({ model, actions: createActions() }, { model, actions: createActions() })).toBe(true);
expect(compare({ model, actions: createActions() }, { model: { ...model, query: "neu" }, actions: createActions() })).toBe(false);
});
it("offers selected and all transfer actions", () => {
+7 -1
View File
@@ -3,7 +3,7 @@ import { isValidElement, type ReactElement, type ReactNode } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import type { DownloadItem, DownloadStatus, UiSnapshot } from "../src/shared/types";
import { appendBandwidthSample, readBandwidthChartPalette, readDownloadSpeedSparklinePalette } from "../src/renderer/App";
import { appendBandwidthSample, getIdleSparklineStroke, readBandwidthChartPalette, readDownloadSpeedSparklinePalette } from "../src/renderer/App";
import {
buildStatisticsViewModel,
type StatisticsMetric
@@ -593,6 +593,12 @@ describe("bandwidth chart palette", () => {
expect(palette).toEqual({ accent: "rgb(74, 222, 128)" });
});
it("aligns the idle speed line to one physical pixel at every display scale", () => {
expect(getIdleSparklineStroke(22, 1)).toEqual({ y: 20.5, lineWidth: 1 });
expect(getIdleSparklineStroke(22, 1.25)).toEqual({ y: 20.4, lineWidth: 0.8 });
expect(getIdleSparklineStroke(22, 2)).toEqual({ y: 20.25, lineWidth: 0.5 });
});
it("labels the live chart and slows redraws when reduced motion is requested", () => {
const source = readFileSync(new URL("../src/renderer/App.tsx", import.meta.url), "utf8");
const chartBlock = source.slice(source.indexOf("const BandwidthChart"), source.indexOf("interface DownloadSpeedSparklineProps"));