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
14 changes: 14 additions & 0 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@ For a browser trace, run `pnpm dev:e2e` and then
mounts, history pagination and the expanded note body. Timings include a
paint opportunity and the Search debounce. These are post-open interactions.
The production cold-open apply stage in #602 is outside these measurements.

## Task detail, filter editor and bulk selection at 10,000 tasks

Run `rpnpm bench:editor-interactions`. Each of three runs seeds a fresh demo
repository. The React/jsdom benchmark opens the last task in navigation order,
makes ten successive title changes and flushes on blur. It opens the
view editor's Filter section and applies a Bases expression for each of tags,
contexts, projects and status, checks the match counts, and changes the view
name five times. It then registers the 10,000 rows, selects 32 in succession
and applies a priority change through the bulk command. Each run reports the
number of navigation IDs read during typing, preview evaluations during
renaming and elapsed milliseconds. Timings include the demo repository and
React updates. Browser painting, native sync and network latency need separate
measurements.
160 changes: 160 additions & 0 deletions benchmarks/editor-interactions.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { expect, it, vi } from "vitest";
import {
act,
fireEvent,
render,
screen,
waitFor,
within,
} from "../src/test/render";
import * as viewPreview from "../src/domain/view-preview";
import { TaskScreen } from "../src/app/task-screen";
import { ViewEditor } from "../src/app/view-editor";
import { RepositoryProvider } from "../src/app/repository-context";
import { TaskSelectionStore } from "../src/app/task-selection-store";
import {
applyBulkEdits,
planTaskChange,
} from "../src/application/bulk-task-edit";
import { DemoTaskRepository } from "../src/demo/demo-task-repository";
import { MemoryMutationJournal } from "../src/test/memory-mutation-journal";

it.runIf(process.env.TASKNOTES_BENCH_INTERACTIONS === "1").each([1, 2, 3])(
"profiles detail, filter editing and bulk selection on 10k tasks (run %i)",
async (run) => {
const preview = vi.spyOn(viewPreview, "previewViewDraft");
const size = 10_000;
const repository = new DemoTaskRepository(0, undefined, {
tasks: (model) =>
Array.from({ length: size }, (_, index) =>
model.create(
{
title: `Task ${index}`,
status: index % 2 ? "open" : "done",
tags: [`tag-${index % 4}`],
contexts: [`context-${index % 4}`],
projects: [`project-${index % 4}`],
},
{ id: String(index), now: "2026-11-01T00:00:00Z" },
),
),
scratchpads: () => [],
});
const tasks = await repository.listSummaries({
status: "all",
limit: size,
});
expect(tasks.length).toBe(size);
let visits = 0;
const order = tasks.map((task) => ({
get id() {
visits++;
return task.id;
},
}));
const id = tasks[size - 1]!.id;
const samples: Record<string, number> = {};
let start = performance.now();
function elapsed(name: string) {
samples[name] = +(performance.now() - start).toFixed(2);
start = performance.now();
}
const journal = new MemoryMutationJournal();
const view = render(
<RepositoryProvider repository={repository} mutationJournal={journal}>
<TaskScreen
id={id}
taskOrder={order}
onBack={vi.fn()}
onMaterialized={vi.fn()}
/>
</RepositoryProvider>,
);
const title = await screen.findByLabelText("Task title", { exact: true });
await screen.findByLabelText("Notes", { exact: true });
elapsed("detail.openMs");
visits = 0;
for (let index = 0; index < 10; index++)
fireEvent.change(title, { target: { value: `Updated ${index}` } });
elapsed("detail.tenKeystrokesMs");
const navigationReads = visits;
fireEvent.blur(title);
await waitFor(async () =>
expect((await repository.get(id))?.title).toBe("Updated 9"),
);
elapsed("detail.blurSaveMs");
start = performance.now();
view.rerender(
<RepositoryProvider repository={repository} mutationJournal={journal}>
<ViewEditor
initialSection="view-filter"
onClose={vi.fn()}
onChanged={async () => {}}
/>
</RepositoryProvider>,
);
const mode = await screen.findByRole("group", {
name: "Filter editor mode",
});
fireEvent.click(within(mode).getByRole("button", { name: "Advanced" }));
const filter = screen.getByLabelText("Filter expression");
elapsed("filter.openMs");
for (const field of ["tags", "contexts", "projects", "status"]) {
const expr =
field === "status"
? 'note.status == "open"'
: `note.${field}.contains("${field.slice(0, -1)}-1")`;
fireEvent.change(filter, { target: { value: expr } });
await screen.findByText(
field === "status"
? /5,?000 tasks match this draft/
: /2,?500 tasks match this draft/,
);
elapsed(`filter.${field}Ms`);
}
const name = screen.getByLabelText("View name");
preview.mockClear();
for (let index = 0; index < 5; index++)
fireEvent.change(name, { target: { value: `Renamed ${index}` } });
elapsed("filter.renameFiveKeystrokesMs");

const renamePreviewCalls = preview.mock.calls.length;
const store = new TaskSelectionStore();
const owner = {};
start = performance.now();
store.register(owner, tasks);
elapsed("bulk.registerMs");
for (const task of tasks.slice(0, 32)) {
store.toggle(task.id);
void store.selectedTasks;
}
elapsed("bulk.select32Ms");
await act(async () => {
const { receipts, failures } = await applyBulkEdits(
store.selectedTasks,
(task) => planTaskChange(task, { kind: "priority", value: "high" }),
{
getSummary: (id) => repository.getSummary(id),
updateTask: (id, input) => repository.update(id, input),
setTaskArchived: (id, archived) =>
repository.setArchived(id, archived),
},
"Changed",
);
elapsed("bulk.apply32Ms");
expect(failures).toEqual([]);
expect(receipts).toHaveLength(32);
});
view.unmount();
console.log(
JSON.stringify({
run,
size,
navigationReads,
renamePreviewCalls,
...samples,
}),
);
},
120_000,
);
13 changes: 13 additions & 0 deletions e2e/offline-device.fixture.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Offline edit test device</title>
</head>
<body>
<script type="module">
import { smokeDevice } from "../src/test/next-entry-smoke-fixture.tsx";
window.offlineTestDevice = smokeDevice(window.__TASKNOTES_NEXT_SMOKE__);
</script>
</body>
</html>
121 changes: 121 additions & 0 deletions e2e/offline-edit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { expect, test } from "./local-test";
import type { smokeDevice } from "../src/test/next-entry-smoke-fixture";

declare global {
interface Window {
offlineTestDevice?: ReturnType<typeof smokeDevice>;
}
}

test("a refused edit survives a pending reload and keeps the peer's other fields", async ({
page: host,
context,
}) => {
test.setTimeout(90_000);
const id = "shared-task";
const path = "TaskNotes/shared.md";
const input = {
records: [
{
path,
frontmatter: {
id,
title: "Shared task",
status: "open",
priority: "normal",
timeEstimate: 25,
tags: ["task"],
type: "task",
mobileRevision: 1,
},
body: "Initial notes",
},
],
slowConfirmation: true,
};
// The host owns only the SDK fixture's replica and write ledger. Reloading
// the app tab destroys its React tree, editor, repository and SDK client.
await context.addInitScript((input) => {
window.__TASKNOTES_NEXT_SMOKE__ = input;
// Resolve on admission. Chromium can install the init script before the
// opener is available on a newly created document.
window.__TASKNOTES_OPEN_DEVICE__ = (page) =>
window.opener.offlineTestDevice.open(page);
}, input);
await host.goto("e2e/offline-device.fixture.html");
await host.waitForFunction(() => !!window.offlineTestDevice);
const popup = context.waitForEvent("page");
await host.evaluate(() => {
window.open("../task/shared-task");
});
const page = await popup;
const open = () =>
page
.getByRole("button", { name: "Open synced fixture collection" })
.click();
const title = page.getByRole("textbox", { name: "Task title", exact: true });
const notes = page.getByRole("textbox", { name: "Notes", exact: true });
await open();
await page.getByRole("button", { name: "Edit Time" }).click();
await page.getByLabel("Estimate (minutes)").fill("");
await notes.fill("Offline body");
await title.fill("Offline title");
await title.press("Tab");
await expect
.poll(() =>
page.evaluate(
() =>
window.__TASKNOTES_NEXT_SMOKE_CONTROL__!.records()[0]?.frontmatter
.title,
),
)
.toBe("Offline title");
await expect(
page.getByRole("button", {
name: "Saved on this device; waiting for sync",
}),
).toBeVisible();
await page.reload();
await open();
await expect(
page.getByRole("button", { name: "Restore unsaved edits" }),
).toBeVisible();
await host.evaluate(async (path) => {
const { ledger, replica } = window.offlineTestDevice!;
const rows = await ledger.list();
if (!rows.length) throw new Error("Missing offline write receipt");
for (const row of rows) replica.reject(row.mutationId);
replica.editElsewhere(path, {
body: "CLI body",
frontmatter: { title: "CLI title", priority: "high", timeEstimate: 40 },
});
replica.stallConfirmations(false);
}, path);
await expect(
page.getByRole("button", { name: "Keep my edit" }),
).toBeVisible();
await expect(notes).toHaveText("Offline body");
// Explicitly revert to the value seen at open. A baseline diff loses this.
await notes.fill("Initial notes");
await page.reload();
await open();
await expect(notes).toHaveText("Initial notes");
await expect(title).toHaveValue("Offline title");
await page.getByRole("button", { name: "Keep my edit" }).click();
await expect
.poll(() =>
page.evaluate(() => {
const record = window.__TASKNOTES_NEXT_SMOKE_CONTROL__!.records()[0]!;
return [
record.frontmatter.title,
record.body,
record.frontmatter.priority,
record.frontmatter.timeEstimate ?? null,
];
}),
)
.toEqual(["Offline title", "Initial notes", "high", null]);
await expect(page.getByRole("button", { name: "Keep my edit" })).toHaveCount(
0,
);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"test:watch": "vitest",
"bench:view-formatting": "TASKNOTES_BENCH_FORMATTING=1 vitest run benchmarks/view-formatting.test.ts benchmarks/view-entry.test.ts",
"bench:view-interactions": "TASKNOTES_BENCH_INTERACTIONS=1 vitest run benchmarks/view-interactions.test.ts",
"bench:editor-interactions": "TASKNOTES_BENCH_INTERACTIONS=1 vitest run benchmarks/editor-interactions.test.tsx",
"bench:recurrence": "TASKNOTES_BENCH_FORMATTING=1 vitest run benchmarks/recurrence-scale.test.ts",
"bench:collections": "tsc -p benchmarks/tsconfig.json && vitest run --config benchmarks/vitest.config.ts",
"test:e2e": "playwright test",
Expand Down
Loading
Loading