Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions packages/studio-server/src/history/pruneHistories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function tempDir(prefix: string): string {
}

const DAY_MS = 24 * 60 * 60 * 1000;
// Date.now() rounds down to the millisecond; a file written in that millisecond can carry a later mtime.
const pastKeepWindow = () => Date.now() + 1 + KEEP_GONE_PROJECT_HISTORY_MS;

async function projectWithHistory(
historyRoot: string,
Expand Down Expand Up @@ -105,7 +107,7 @@ describe("pruneGoneProjectHistories", () => {
expect(await prunedIds(historyRoot, { ...elsewhere, now: Date.now() + 13 * DAY_MS })).toEqual(
[],
);
expect(await prunedIds(historyRoot, { ...elsewhere, now: Date.now() + 14 * DAY_MS })).toEqual([
expect(await prunedIds(historyRoot, { ...elsewhere, now: pastKeepWindow() })).toEqual([
gone.id,
]);
});
Expand Down Expand Up @@ -178,7 +180,7 @@ describe("pruneGoneProjectHistories", () => {

chmodSync(locked, 0o000);
try {
const later = Date.now() + KEEP_GONE_PROJECT_HISTORY_MS;
const later = pastKeepWindow();
const onError = (error: unknown) => errors.push(error);
expect(await prunedIds(historyRoot, { now: later, onError })).toEqual([gone.id]);
} finally {
Expand Down Expand Up @@ -206,7 +208,7 @@ describe("pruneGoneProjectHistories", () => {
rmSync(join(mountPoint.projectDir, ".hyperframes"), { recursive: true, force: true });
rmSync(dirname(deleted.projectDir), { recursive: true, force: true });

const later = Date.now() + KEEP_GONE_PROJECT_HISTORY_MS;
const later = pastKeepWindow();
expect(await prunedIds(historyRoot, { tempDir: historyRoot, now: later })).toEqual([
deleted.id,
]);
Expand All @@ -227,7 +229,7 @@ describe("pruneGoneProjectHistories", () => {
rmSync(folderGone.projectDir, { recursive: true, force: true });
rmSync(dirname(parentGone.projectDir), { recursive: true, force: true });

const later = Date.now() + KEEP_GONE_PROJECT_HISTORY_MS;
const later = pastKeepWindow();
expect(await prunedIds(historyRoot, { tempDir: historyRoot, now: later })).toEqual([
emptied.id,
]);
Expand Down
2 changes: 1 addition & 1 deletion packages/studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@hyperframes/studio-server": "workspace:*",
"@mcp-b/global": "^5.0.1",
"@phosphor-icons/react": "^2.1.10",
"@tanstack/react-virtual": "^3.14.6",
"@tanstack/react-virtual": "^3.14.13",
"bpm-detective": "^2.0.5",
"cn": "0.2.4",
"dockview-react": "8.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import React, { act } from "react";
import { createRoot } from "react-dom/client";
import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
import {
elementScroll,
observeElementOffset,
observeElementRect,
Virtualizer,
} from "@tanstack/react-virtual";
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { createTimelineRowGeometry, RULER_H, TRACKS_TOP_PAD } from "./timelineLayout";
import { extractTimelineVirtualRowRange, useTimelineVirtualRows } from "./useTimelineVirtualRows";
import type { TimelineScrollViewportSnapshot } from "./useTimelineScrollViewport";
Expand Down Expand Up @@ -203,4 +209,27 @@ describe("useTimelineVirtualRows", () => {
expect(rows.some((row) => row.index === 500)).toBe(false);
act(() => root.unmount());
});

// A scroll-end timer left running fires into the torn-down test window ("window is not defined").
it("gets no virtualizer change after unmount from a scroll just before it", async () => {
const scroll = createScrollElement(0);
const onChange = vi.fn();
const virtualizer = new Virtualizer<HTMLDivElement, Element>({
count: 100,
getScrollElement: () => scroll,
estimateSize: () => 48,
scrollToFn: elementScroll,
observeElementRect,
observeElementOffset,
onChange,
});
const unmount = virtualizer._didMount();
virtualizer._willUpdate();
scroll.dispatchEvent(new Event("scroll"));
unmount();
onChange.mockClear();

await new Promise((settle) => setTimeout(settle, 200));
expect(onChange).not.toHaveBeenCalled();
});
});
Loading