From c1bb325e6ea21fd8b6af854864b4dd5f55589263 Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sat, 28 Nov 2026 21:22:14 +1100 Subject: [PATCH] Preserve explicit task edits through offline rejection and bound editor work --- benchmarks/README.md | 14 ++ benchmarks/editor-interactions.test.tsx | 160 +++++++++++++++++++ e2e/offline-device.fixture.html | 13 ++ e2e/offline-edit.spec.ts | 121 +++++++++++++++ package.json | 1 + src/app/bulk-task-actions.tsx | 63 ++++---- src/app/task-edit-recovery.ts | 167 ++++++++++++-------- src/app/task-editor-draft.test.ts | 25 +++ src/app/task-screen.reload.test.tsx | 45 ++++++ src/app/task-screen.test.tsx | 16 ++ src/app/task-screen.tsx | 186 ++++++++++++----------- src/app/task-selection-store.ts | 61 +++++--- src/app/task-selection.tsx | 2 +- src/app/view-editor.tsx | 10 +- src/components/recovered-edit-notice.tsx | 1 + src/domain/task.ts | 2 + src/domain/tasknotes-model.test.ts | 17 +++ src/domain/tasknotes-model.ts | 19 ++- src/domain/view-preview.ts | 19 ++- src/test/next-entry-smoke-fixture.tsx | 53 +++++-- 20 files changed, 769 insertions(+), 226 deletions(-) create mode 100644 benchmarks/editor-interactions.test.tsx create mode 100644 e2e/offline-device.fixture.html create mode 100644 e2e/offline-edit.spec.ts diff --git a/benchmarks/README.md b/benchmarks/README.md index ffe2bb74..e2bb0aaa 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -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. diff --git a/benchmarks/editor-interactions.test.tsx b/benchmarks/editor-interactions.test.tsx new file mode 100644 index 00000000..c62e82a0 --- /dev/null +++ b/benchmarks/editor-interactions.test.tsx @@ -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 = {}; + 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( + + + , + ); + 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( + + {}} + /> + , + ); + 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, +); diff --git a/e2e/offline-device.fixture.html b/e2e/offline-device.fixture.html new file mode 100644 index 00000000..c6ed9d8d --- /dev/null +++ b/e2e/offline-device.fixture.html @@ -0,0 +1,13 @@ + + + + + Offline edit test device + + + + + diff --git a/e2e/offline-edit.spec.ts b/e2e/offline-edit.spec.ts new file mode 100644 index 00000000..c337225a --- /dev/null +++ b/e2e/offline-edit.spec.ts @@ -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; + } +} + +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, + ); +}); diff --git a/package.json b/package.json index 50b7733d..a94a6dee 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app/bulk-task-actions.tsx b/src/app/bulk-task-actions.tsx index 862cf4cf..dedb19c0 100644 --- a/src/app/bulk-task-actions.tsx +++ b/src/app/bulk-task-actions.tsx @@ -5,6 +5,7 @@ import { useEffectEvent, useId, useLayoutEffect, + useMemo, useRef, useState, useSyncExternalStore, @@ -97,37 +98,47 @@ export function BulkTaskActions({ const deletionFailureHandled = useRef(null); const undoRef = useRef(null); const selected = store.selectedTasks; - const eligible = selected.filter( - (task) => !task.recurrence && !task.recurrenceParent, + const eligible = useMemo( + () => selected.filter((task) => !task.recurrence && !task.recurrenceParent), + [selected], ); const excluded = selected.length - eligible.length; const hasSelection = selected.length > 0; - const sharedPriority = eligible.every( - (task) => task.priority === eligible[0]?.priority, - ) - ? (eligible[0]?.priority ?? "") - : ""; - const sharedStatus = eligible.every( - (task) => task.status === eligible[0]?.status, - ) - ? (eligible[0]?.status ?? "") - : ""; - // The tags that mark a record as a task or as archived are not labels. - const reservedTags = [ - configuration.defaults.taskTag, - configuration.fieldMapping.archiveTag, - ]; - // A tag every selected task carries is offered for removal; any other is added. - const sharedTags = (eligible[0]?.tags ?? []).filter( - (tag) => - !reservedTags.includes(tag) && - eligible.every((task) => task.tags.includes(tag)), + const taskTag = configuration.defaults.taskTag; + const archiveTag = configuration.fieldMapping.archiveTag; + const { sharedPriority, sharedStatus, sharedTags, selectionTags } = + useMemo(() => { + const first = eligible[0]; + const sharedTags = (first?.tags ?? []).filter( + (tag) => + tag !== taskTag && + tag !== archiveTag && + eligible.every((task) => task.tags.includes(tag)), + ); + return { + sharedTags, + selectionTags: [...new Set(eligible.flatMap((task) => task.tags))], + sharedPriority: eligible.every( + (task) => task.priority === first?.priority, + ) + ? (first?.priority ?? "") + : "", + sharedStatus: eligible.every((task) => task.status === first?.status) + ? (first?.status ?? "") + : "", + }; + }, [eligible, taskTag, archiveTag]); + const otherTags = useMemo( + () => + [...new Set([...selectionTags, ...knownTags])].filter( + (tag) => + !sharedTags.includes(tag) && tag !== taskTag && tag !== archiveTag, + ), + [selectionTags, knownTags, sharedTags, taskTag, archiveTag], ); - const otherTags = [ - ...new Set([...eligible.flatMap((task) => task.tags), ...knownTags]), - ].filter((tag) => !sharedTags.includes(tag) && !reservedTags.includes(tag)); const namedTag = newTag?.trim().replace(/^#+/, "") ?? ""; - const canAddNamedTag = Boolean(namedTag) && !reservedTags.includes(namedTag); + const canAddNamedTag = + Boolean(namedTag) && namedTag !== taskTag && namedTag !== archiveTag; const shownNotice = notice?.navigationKey === navigationKey ? notice : null; const currentNavigation = useRef(navigationKey); useEffect(() => { diff --git a/src/app/task-edit-recovery.ts b/src/app/task-edit-recovery.ts index 3214716e..3e2f16c6 100644 --- a/src/app/task-edit-recovery.ts +++ b/src/app/task-edit-recovery.ts @@ -1,22 +1,78 @@ import { historyScope } from "./search-history"; import type { CollectionInfo } from "../application/ports/task-repository"; +import type { UpdateTaskInput } from "../domain/task"; import type { Draft } from "./task-editor-draft"; -/** - * A copy of the task edits this device has not yet handed to mdbase. - * - * Saving a task goes through reads and the SDK before the write is captured on - * the device, which a reload or a closed tab can interrupt. Each edit is - * therefore written here synchronously, and removed only once mdbase has - * captured the save (or the person discards it). On the next open, edits that - * the task does not already show are offered back for review. - */ +/** Only explicit editor changes. Null represents a clear, including after JSON storage. */ +export type TaskEdit = Pick< + UpdateTaskInput, + keyof Draft | "customPropertyPatch" +>; + +export function mergeTaskEdits(first: TaskEdit, second: TaskEdit): TaskEdit { + return { + ...first, + ...second, + ...(first.customPropertyPatch && second.customPropertyPatch + ? { + customPropertyPatch: { + ...first.customPropertyPatch, + ...second.customPropertyPatch, + }, + } + : {}), + }; +} + +export function applyTaskEdit(base: Draft, edit: TaskEdit): Draft { + const { customPropertyPatch, ...fields } = edit; + const next = { + ...base, + ...Object.fromEntries( + Object.entries(fields).map(([key, value]) => [key, value ?? undefined]), + ), + }; + if (customPropertyPatch) { + next.customProperties = { ...next.customProperties }; + for (const [key, value] of Object.entries(customPropertyPatch)) { + if (value == null) delete next.customProperties[key]; + else next.customProperties[key] = value; + } + } + return next; +} + +export function editorPatch(base: Draft, patch: Partial): TaskEdit { + const { customProperties, ...fields } = patch; + const edit: TaskEdit = Object.fromEntries( + Object.entries(fields) + .filter(([key, value]) => !same(base[key as keyof Draft], value)) + .map(([key, value]) => [key, value ?? null]), + ); + if (customProperties) { + const changes = Object.fromEntries( + [ + ...new Set([ + ...Object.keys(base.customProperties), + ...Object.keys(customProperties), + ]), + ] + .filter( + (key) => !same(base.customProperties[key], customProperties[key]), + ) + .map((key) => [key, customProperties[key] ?? null]), + ); + if (Object.keys(changes).length) edit.customPropertyPatch = changes; + } + return edit; +} + export interface StoredTaskEdit { readonly version: 1; readonly savedAt: string; - /** Only the fields that differ from the task as it was opened. */ - readonly fields: Partial; + /** Fields edited locally and still awaiting capture, confirmation or review. */ + readonly fields: TaskEdit; } export interface TaskEditStorage { @@ -59,63 +115,21 @@ function defaultStorage(): TaskEditStorage | undefined { } function same(left: unknown, right: unknown): boolean { - return JSON.stringify(left ?? null) === JSON.stringify(right ?? null); -} - -/** The fields of `draft` that differ from `base`. */ -export function changedFields(base: Draft, draft: Draft): Partial { - const out: Record = {}; - for (const field of Object.keys(draft) as (keyof Draft)[]) - if (!same(base[field], draft[field])) out[field] = draft[field]; - return out as Partial; -} - -/** - * Follow a newer version of the task in every field without a local edit, and - * return the draft to show, or null when it is unchanged. - * - * `known` holds the version the editor last saw, field by field. A field whose - * draft differs from it is an edit in progress and is kept, unless it already - * equals the incoming value (this editor's own save). With nothing unsaved or - * saving (`pending` false), every local value has been saved, so any - * difference from the incoming version is newer or normalised data. Adopted - * fields also move `opened`, so they never count as this person's edit. - */ -export function followIncomingDraft( - baselines: { known: { current: Draft }; opened: { current: Draft } }, - local: Draft, - remote: Draft, - pending: boolean, -): Draft | null { - const { known, opened } = baselines; - let adopted: Partial; - if (!pending) { - adopted = changedFields(local, remote); - known.current = remote; - } else { - const editedLocally = changedFields(known.current, local); - const differsFromRemote = changedFields(remote, local); - const nextKnown: Record = { ...known.current }; - const fields: Record = {}; - for (const field of Object.keys(changedFields(known.current, remote))) { - if (field in editedLocally && field in differsFromRemote) continue; - nextKnown[field] = remote[field as keyof Draft]; - if (!(field in editedLocally)) - fields[field] = remote[field as keyof Draft]; - } - known.current = nextKnown as Draft; - adopted = fields as Partial; - } - if (!Object.keys(adopted).length) return null; - opened.current = { ...opened.current, ...adopted }; - return { ...local, ...adopted }; + if ((left ?? null) === (right ?? null)) return true; + return ( + left != null && + right != null && + typeof left === "object" && + typeof right === "object" && + JSON.stringify(left) === JSON.stringify(right) + ); } /** False when this browser cannot keep the copy (storage full or blocked). */ export function writeTaskEdit( scope: string, taskId: string, - fields: Partial, + fields: TaskEdit, storage = defaultStorage(), ): boolean { if (!storage) return false; @@ -170,15 +184,38 @@ export function readTaskEdit( parsed?.version === 1 && parsed.fields && typeof parsed.fields === "object" - ) - stored = parsed as StoredTaskEdit; + ) { + // Older copies contained the whole custom-properties object. Missing + // keys carry no deletion intent and can belong to a newer peer edit. + const { customProperties, customPropertyPatch, ...fields } = + parsed.fields; + stored = { + version: 1, + savedAt: parsed.savedAt ?? "", + fields: { + ...Object.fromEntries( + Object.entries(fields).filter(([key]) => + Object.hasOwn(current, key), + ), + ), + ...(customProperties || customPropertyPatch + ? { + customPropertyPatch: { + ...customProperties, + ...customPropertyPatch, + }, + } + : {}), + }, + }; + } } catch { stored = null; } const fields = stored ? unconfirmed ? stored.fields - : changedFields(current, { ...current, ...stored.fields }) + : editorPatch(current, applyTaskEdit(current, stored.fields)) : {}; if (!stored || !Object.keys(fields).length) { clearTaskEdit(scope, taskId, storage); diff --git a/src/app/task-editor-draft.test.ts b/src/app/task-editor-draft.test.ts index a5e4ab7e..f8de459e 100644 --- a/src/app/task-editor-draft.test.ts +++ b/src/app/task-editor-draft.test.ts @@ -1,3 +1,9 @@ +import { + applyTaskEdit, + readTaskEdit, + writeTaskEdit, + tabTaskEdits, +} from "./task-edit-recovery"; import { afterEach, describe, expect, it, vi } from "vitest"; import { TaskNotesTaskModel } from "../domain/tasknotes-model"; import { defaultTaskCollectionConfiguration } from "../domain/task-configuration"; @@ -57,3 +63,22 @@ describe("task schedule summary", () => { ).toBe("Normal · Scheduled Today · Due Fri"); }); }); + +it("restores legacy custom property edits without clearing peer-only keys", () => { + const storage = tabTaskEdits(); + const current = toDraft( + new TaskNotesTaskModel().create({ title: "Shared" }, { id: "shared" }), + ); + current.customProperties = { owner: "CLI", energy: 1 }; + writeTaskEdit( + "scope", + "shared", + { customProperties: { energy: 2 } }, + storage, + ); + const recovered = readTaskEdit("scope", "shared", current, storage, true)!; + expect(applyTaskEdit(current, recovered.fields).customProperties).toEqual({ + owner: "CLI", + energy: 2, + }); +}); diff --git a/src/app/task-screen.reload.test.tsx b/src/app/task-screen.reload.test.tsx index d20a3673..c895f790 100644 --- a/src/app/task-screen.reload.test.tsx +++ b/src/app/task-screen.reload.test.tsx @@ -193,6 +193,51 @@ describe("TaskScreen across an immediate reload", () => { second.unload(); }); + it("recovers a cleared estimate after a failed offline save and a concurrent body edit", async () => { + const mdbase = await createTestMdbase(); + const replica = mdbase.fixture.replica(); + const first = await openPage( + replica, + mdbase.fixture.client(), + async (repository) => + ( + await repository.create({ + title: "Shared estimate", + timeEstimate: 30, + body: "Original", + }) + ).id, + ); + const path = (await first.repository.get(first.id))!.path; + const blocked = vi + .spyOn(first.repository, "update") + .mockRejectedValue(new Error("Offline")); + fireEvent.click(await screen.findByRole("button", { name: "Edit Time" })); + fireEvent.change(await screen.findByLabelText("Estimate (minutes)"), { + target: { value: "" }, + }); + await waitFor(() => expect(blocked).toHaveBeenCalled()); + first.unload(); + replica.editElsewhere(path, { body: "Newer CLI body" }); + const second = await openPage( + replica, + await reconnect(replica), + async () => first.id, + ); + fireEvent.click( + await screen.findByRole("button", { name: "Restore unsaved edits" }), + ); + await waitFor( + async () => { + const saved = await second.repository.get(first.id); + expect(saved?.body).toBe("Newer CLI body"); + expect(saved?.timeEstimate).toBeUndefined(); + }, + { timeout: 3000 }, + ); + second.unload(); + }); + it.each(["available", "unavailable"] as const)( "waits for the recovery scope before exposing title editing (%s)", async (outcome) => { diff --git a/src/app/task-screen.test.tsx b/src/app/task-screen.test.tsx index 2826d371..174316e3 100644 --- a/src/app/task-screen.test.tsx +++ b/src/app/task-screen.test.tsx @@ -606,6 +606,22 @@ describe("TaskScreen with a change made in another tab", () => { await act(async () => void (await repository.refresh())); } + it("preserves a peer body update arriving after the title save starts", async () => { + const title = await screen.findByLabelText("Task title", { exact: true }); + const update = repository.update.bind(repository); + vi.spyOn(repository, "update").mockImplementationOnce(async (...args) => { + fixture.replica.editElsewhere(task.path, { body: "From the CLI" }); + return update(...args); + }); + fireEvent.change(title, { target: { value: "Local title" } }); + fireEvent.blur(title); + await waitFor(async () => { + const saved = await repository.get(task.id); + expect(saved?.title).toBe("Local title"); + expect(saved?.body).toBe("From the CLI"); + }); + }); + it("shows a title changed elsewhere after this tab saved its own", async () => { const title = await screen.findByLabelText("Task title", { exact: true }); fireEvent.change(title, { target: { value: "Beta" } }); diff --git a/src/app/task-screen.tsx b/src/app/task-screen.tsx index 01aeee86..24063516 100644 --- a/src/app/task-screen.tsx +++ b/src/app/task-screen.tsx @@ -57,14 +57,16 @@ import { rememberOpenedTask } from "./search-history"; import { TaskPaneNavigation } from "./task-editor-layout"; import { formatOccurrenceDate, toDraft, type Draft } from "./task-editor-draft"; import { - changedFields, - followIncomingDraft, + applyTaskEdit, + editorPatch, + mergeTaskEdits, + type TaskEdit, readTaskEdit, writeTaskEdit, type StoredTaskEdit, } from "./task-edit-recovery"; -import type { Task, UpdateTaskInput } from "../domain/task"; +import type { Task } from "../domain/task"; import type { FieldCompletionRequest } from "../domain/completion"; const taskNotesEditor = preloadable( @@ -317,11 +319,12 @@ function TaskEditor({ const draftRef = useRef(draft); const dirtyRef = useRef(false); const savesInFlight = useRef(new Map>()); - // The task as opened; local copies hold only the fields edited since. - const openedDraft = useRef(draft); - // The version this editor last saw from mdbase, field by field. A field - // whose draft still matches it has no local edit and follows newer versions. - const knownDraft = useRef(draft); + // Keep explicit intent until the receipt settles. Equality with an optimistic + // snapshot (including a change back to the original value) is not confirmation. + const localEdit = useRef({}); + // A later save submits only what changed since capture. The recovery copy + // also includes earlier writes still waiting for their receipts. + const unsent = useRef({}); const editScope = useRef(recoveryScope); const { onTaskDraft, taskEditStorage } = useContext(CollectionGateContext) ?? {}; @@ -336,12 +339,10 @@ function TaskEditor({ (unsaved: boolean) => { const scope = editScope.current; if (!scope) return; - const fields = { - ...recoveredRef.current?.fields, - ...(unsaved - ? changedFields(openedDraft.current, draftRef.current) - : {}), - }; + const fields = mergeTaskEdits( + recoveredRef.current?.fields ?? {}, + unsaved ? localEdit.current : {}, + ); onTaskDraft?.(fields); const kept = writeTaskEdit(scope, task.id, fields, taskEditStorage); if (mounted.current) setBackupUnavailable(!kept); @@ -378,9 +379,34 @@ function TaskEditor({ }, []); const persist = useCallback( - (value: Draft, version: number): Promise => { + function save( + value: Draft, + version: number, + reviewedRevision?: string | number, + ): Promise { const existing = savesInFlight.current.get(version); if (existing) return existing; + const previous = [...savesInFlight.current.values()].at(-1); + if (previous) + return previous.then(() => + dirtyRef.current + ? save(draftRef.current, editVersion.current, reviewedRevision) + : undefined, + ); + const target = { kind: "task", id: task.id } as const; + if ( + reviewedRevision === undefined && + repository.writeState?.(target) === "failed" && + repository.writeRejection?.(target)?.changedElsewhere + ) + return Promise.reject( + new Error( + t({ + message: + "Keep or discard your unsaved edit before making another change.", + }), + ), + ); if (!value.title.trim()) { if (mounted.current) { setSaveError(t({ message: "Add a title before leaving this task." })); @@ -392,35 +418,17 @@ function TaskEditor({ setSaveState("saving"); setSaveError(null); } + const input = unsent.current; + unsent.current = {}; const run = (async () => { try { - const input: UpdateTaskInput = { - title: value.title, - status: value.status, - priority: value.priority, - due: value.due ?? null, - scheduled: value.scheduled ?? null, - body: value.body, - tags: value.tags, - contexts: value.contexts, - projects: value.projects, - // Only an actual assignment edit writes the field. - ...(sameIds(value.assignees ?? [], task.assignees ?? []) - ? {} - : { assignees: value.assignees ?? [] }), - blockedBy: value.blockedBy, - recurrence: value.recurrence ?? null, - recurrenceAnchor: value.recurrenceAnchor, - occurrenceMaterialization: value.occurrenceMaterialization, - occurrenceNextTrigger: value.occurrenceNextTrigger, - occurrenceTemplate: value.occurrenceTemplate ?? null, - occurrencePastHorizon: value.occurrencePastHorizon ?? null, - occurrenceFutureHorizon: value.occurrenceFutureHorizon ?? null, - reminders: value.reminders, - timeEstimate: value.timeEstimate ?? null, - customProperties: value.customProperties, - }; - await updateTask(task.id, input); + if (reviewedRevision !== undefined) + await updateTask(task.id, input, { + expectedRevision: reviewedRevision, + }); + else await updateTask(task.id, input); + if (!repository.writeState?.(target)) + localEdit.current = unsent.current; if (editVersion.current === version) { // Backup cleanup belongs to the mounted editor's confirmation // effect, never a late completion from an unloaded editor. @@ -431,6 +439,7 @@ function TaskEditor({ } } } catch (reason) { + unsent.current = mergeTaskEdits(input, unsent.current); const error = reason instanceof Error ? reason : new Error(String(reason)); if (mounted.current && editVersion.current === version) { @@ -445,7 +454,7 @@ function TaskEditor({ savesInFlight.current.set(version, run); return run; }, - [task.assignees, task.id, updateTask, t], + [repository, task.id, updateTask, t], ); // Once mdbase confirms every save, the device copy is no longer needed. @@ -456,6 +465,7 @@ function TaskEditor({ repository.writeState?.({ kind: "task", id: task.id }) ) return; + localEdit.current = {}; if (!recovered) recoveredRef.current = null; storeEdit(false); }, [dirty, recovered, repository, storeEdit, task.id, writeState]); @@ -500,6 +510,9 @@ function TaskEditor({ ); function change(patch: Partial) { + const edited = editorPatch(draftRef.current, patch); + localEdit.current = mergeTaskEdits(localEdit.current, edited); + unsent.current = mergeTaskEdits(unsent.current, edited); setSaveState("saving"); editVersion.current += 1; const next = { ...draftRef.current, ...patch }; @@ -516,13 +529,18 @@ function TaskEditor({ // Hide the choice, but keep these explicit fields until confirmation. // They may equal an optimistic baseline that head later rolls back. setRecovered(null); - if (edit) change(edit.fields); + if (edit) { + localEdit.current = mergeTaskEdits(edit.fields, localEdit.current); + unsent.current = mergeTaskEdits(edit.fields, unsent.current); + recoveredRef.current = null; + change(applyTaskEdit(draftRef.current, localEdit.current)); + } } function discardRecoveredEdit() { recoveredRef.current = null; setRecovered(null); - storeEdit(dirtyRef.current); + storeEdit(true); } // An edit refused after a reload comes back from the device copy, so the @@ -548,16 +566,10 @@ function TaskEditor({ // does. A refused save keeps its own review flow. const followIncomingTask = useEffectEvent((incoming: Task) => { if (rejected) return; - const next = followIncomingDraft( - { known: knownDraft, opened: openedDraft }, - draftRef.current, - { - ...toDraft(incoming), - ...(writeState ? recoveredRef.current?.fields : {}), - }, - dirtyRef.current || savesInFlight.current.size > 0 || !!writeState, - ); - if (!next) return; + const base = toDraft(incoming); + const pending = + dirtyRef.current || savesInFlight.current.size > 0 || !!writeState; + const next = pending ? applyTaskEdit(base, localEdit.current) : base; draftRef.current = next; setDraft(next); }); @@ -585,10 +597,16 @@ function TaskEditor({ try { // Only the fields this person changed go on top of the latest version, // so a change made elsewhere to other fields is kept too. - const mine = { - ...recoveredRef.current?.fields, - ...changedFields(openedDraft.current, draftRef.current), - }; + const latest = await repository.get(task.id); + if (!latest) + throw new Error( + translate({ message: "This task is no longer available." }), + ); + if (!mounted.current) return; + const mine = mergeTaskEdits( + recoveredRef.current?.fields ?? {}, + localEdit.current, + ); if (!Object.keys(mine).length) throw new Error( translate({ @@ -596,21 +614,19 @@ function TaskEditor({ "Your edit is no longer available on this device. Discard it to load the latest version.", }), ); - const latest = await repository.get(task.id); - if (!latest) - throw new Error( - translate({ message: "This task is no longer available." }), - ); - if (!mounted.current) return; const base = toDraft(latest); - const next = { ...base, ...mine }; - openedDraft.current = base; - knownDraft.current = base; + const next = applyTaskEdit(base, mine); + localEdit.current = mine; + unsent.current = mine; draftRef.current = next; setDraft(next); editVersion.current += 1; storeEdit(true); - await persist(next, editVersion.current); + await persist( + next, + editVersion.current, + latest.recordVersion ?? latest.revision, + ); } catch (reason) { if (mounted.current) setResolveError( @@ -625,16 +641,18 @@ function TaskEditor({ if (resolving) return; setResolving(true); setResolveError(null); + const version = editVersion.current; try { const latest = await repository.get(task.id); if (!latest) throw new Error( translate({ message: "This task is no longer available." }), ); - if (!mounted.current) return; + if (!mounted.current || version !== editVersion.current) return; editVersion.current += 1; const next = toDraft(latest); - knownDraft.current = next; + localEdit.current = {}; + unsent.current = {}; draftRef.current = next; dirtyRef.current = false; setDraft(next); @@ -664,15 +682,9 @@ function TaskEditor({ requireChoice(); const embed = `!${reference}`; if (draftRef.current.body.includes(embed)) return; - editVersion.current += 1; - const version = editVersion.current; const body = `${draftRef.current.body.trimEnd()}${draftRef.current.body.trim() ? "\n\n" : ""}${embed}\n`; - const next = { ...draftRef.current, body }; - draftRef.current = next; - dirtyRef.current = true; - setDraft(next); - setDirty(true); - await persist(next, version); + change({ body }); + await persist(draftRef.current, editVersion.current); } const refused = Boolean(rejection); @@ -734,8 +746,13 @@ function TaskEditor({ } } - const currentIndex = taskOrder.findIndex( - (target) => target.id === task.id && target.occurrence === occurrenceDate, + const currentIndex = useMemo( + () => + taskOrder.findIndex( + (target) => + target.id === task.id && target.occurrence === occurrenceDate, + ), + [taskOrder, task.id, occurrenceDate], ); const previousTask = currentIndex > 0 ? taskOrder[currentIndex - 1] : undefined; @@ -1200,10 +1217,3 @@ function useDetailsBesideWork(): boolean { () => false, ); } - -function sameIds(left: readonly string[], right: readonly string[]): boolean { - return ( - left.length === right.length && - left.every((value, index) => value === right[index]) - ); -} diff --git a/src/app/task-selection-store.ts b/src/app/task-selection-store.ts index 6e5dc331..45a397f8 100644 --- a/src/app/task-selection-store.ts +++ b/src/app/task-selection-store.ts @@ -19,41 +19,51 @@ export class TaskSelectionStore { }; snapshot = () => this.version; isSelected = (id: string) => this.selected.has(id); + private byId = new Map(); + private order: string[] = []; + private selectedSnapshot?: TaskSummary[]; get tasks(): TaskSummary[] { - return [ - ...new Map( - [...this.lists.values()].flatMap((tasks) => - tasks.map((task) => [task.id, task] as const), - ), - ).values(), - ]; + return Array.from(this.byId.values(), (row) => row.task); } - get ids(): string[] { - return this.tasks.map((task) => task.id); + get ids(): readonly string[] { + return this.order; } - get selectedTasks(): TaskSummary[] { - return this.tasks.filter((task) => this.selected.has(task.id)); + get selectedTasks(): readonly TaskSummary[] { + return (this.selectedSnapshot ??= [...this.selected] + .map((id) => this.byId.get(id)!) + .sort((left, right) => left.index - right.index) + .map((row) => row.task)); } get count(): number { return this.selected.size; } register(owner: object, tasks: readonly TaskSummary[]) { - const before = this.ids.join("\0"); - const revisions = new Map( - this.selectedTasks.map((task) => [task.id, task.revision]), - ); + if (tasks === this.lists.get(owner)) return; + const previous = this.byId; + const previousOrder = this.order; this.lists.set(owner, tasks); - const ids = new Set(this.ids); - const removed = [...this.selected].some((id) => !ids.has(id)); - this.selected = new Set([...this.selected].filter((id) => ids.has(id))); - if (this.anchor && !ids.has(this.anchor)) this.anchor = null; + this.byId = new Map(); + for (const list of this.lists.values()) + for (const task of list) + this.byId.set(task.id, { + task, + index: this.byId.get(task.id)?.index ?? this.byId.size, + }); + this.order = [...this.byId.keys()]; + this.selectedSnapshot = undefined; + let selectionChanged = false; + for (const id of this.selected) { + const row = this.byId.get(id); + if (!row) this.selected.delete(id); + if (!row || row.task.revision !== previous.get(id)?.task.revision) + selectionChanged = true; + } + if (this.anchor && !this.byId.has(this.anchor)) this.anchor = null; if ( - removed || - before !== this.ids.join("\0") || - this.selectedTasks.some( - (task) => revisions.get(task.id) !== task.revision, - ) + selectionChanged || + previousOrder.length !== this.order.length || + previousOrder.some((id, index) => id !== this.order[index]) ) this.publish(); } @@ -74,7 +84,7 @@ export class TaskSelectionStore { this.publish(); }; toggle(id: string) { - if (this.busy || !this.ids.includes(id)) return; + if (this.busy || !this.byId.has(id)) return; this.mode = true; if (this.selected.has(id)) this.selected.delete(id); else this.selected.add(id); @@ -114,6 +124,7 @@ export class TaskSelectionStore { this.publish(); } private publish() { + this.selectedSnapshot = undefined; this.version++; for (const listener of this.listeners) listener(); } diff --git a/src/app/task-selection.tsx b/src/app/task-selection.tsx index affe82a6..487c3529 100644 --- a/src/app/task-selection.tsx +++ b/src/app/task-selection.tsx @@ -53,7 +53,7 @@ export function TaskSelectionList({ const owner = useRef({}); useLayoutEffect(() => { store?.register(owner.current, enabled ? tasks : []); - }); + }, [store, enabled, tasks]); useLayoutEffect(() => { const token = owner.current; return () => store?.unregister(token); diff --git a/src/app/view-editor.tsx b/src/app/view-editor.tsx index 2c347dc9..ec75cfda 100644 --- a/src/app/view-editor.tsx +++ b/src/app/view-editor.tsx @@ -99,7 +99,15 @@ export function ViewEditor({ const confirmationRef = useRef(null); const focusedInitialEditor = useRef(false); const fingerprint = useMemo(() => draftFingerprint(draft), [draft]); - const deferredDraft = useDeferredValue(draft); + const { dialect, filter, computedProperties, sort } = draft ?? {}; + const previewQuery = useMemo( + () => + dialect && computedProperties && sort + ? { dialect, filter, computedProperties, sort } + : null, + [dialect, filter, computedProperties, sort], + ); + const deferredDraft = useDeferredValue(previewQuery); const livePreview = useMemo( () => deferredDraft && tasks diff --git a/src/components/recovered-edit-notice.tsx b/src/components/recovered-edit-notice.tsx index 833ac0c8..58d8aa05 100644 --- a/src/components/recovered-edit-notice.tsx +++ b/src/components/recovered-edit-notice.tsx @@ -17,6 +17,7 @@ const FIELD_LABELS: Record = { reminders: "Reminders", timeEstimate: "Estimate", customProperties: "Properties", + customPropertyPatch: "Properties", }; /** Edits typed on this device that mdbase had not captured when the page diff --git a/src/domain/task.ts b/src/domain/task.ts index cd44799e..d0941df3 100644 --- a/src/domain/task.ts +++ b/src/domain/task.ts @@ -146,6 +146,8 @@ export interface UpdateTaskInput { sortOrder?: string | null; timeEntries?: TaskTimeEntry[]; customProperties?: Record; + /** Editor changes to individual properties. Null clears the named property. */ + customPropertyPatch?: Record; /** Keep concrete execution dates unchanged during a pattern-only RRULE edit. */ preserveRecurrenceSchedule?: boolean; } diff --git a/src/domain/tasknotes-model.test.ts b/src/domain/tasknotes-model.test.ts index 5e9510ad..6c185952 100644 --- a/src/domain/tasknotes-model.test.ts +++ b/src/domain/tasknotes-model.test.ts @@ -32,6 +32,23 @@ describe("TaskNotes task model app boundary", () => { ], }); + it("merges an editor property change or clear into the latest record", () => { + const peer = model.create( + { + title: "Shared", + customProperties: { energy: 4, client: "CLI" }, + }, + { id: "shared" }, + ); + for (const energy of [1, null]) { + const saved = model.update(peer, { customPropertyPatch: { energy } }); + expect(saved.customProperties.client).toBe("CLI"); + expect(saved.customProperties.energy).toBe(energy ?? undefined); + expect(saved.frontmatter.client).toBe("CLI"); + expect(saved.frontmatter.energy).toBe(energy ?? undefined); + } + }); + it("reads projects: null as an empty project list", () => { const created = model.create({ title: "No project" }, { id: "no-project" }); const task = model.read({ diff --git a/src/domain/tasknotes-model.ts b/src/domain/tasknotes-model.ts index 73efa101..34e6cc49 100644 --- a/src/domain/tasknotes-model.ts +++ b/src/domain/tasknotes-model.ts @@ -452,11 +452,22 @@ export class TaskNotesTaskModel { updates.sortOrder = input.sortOrder ?? undefined; if (input.timeEntries !== undefined) updates.timeEntries = normalizeTimeEntries(input.timeEntries); - if (input.customProperties !== undefined) + const customProperties = input.customPropertyPatch + ? { + ...(input.customProperties ?? original.customProperties), + ...input.customPropertyPatch, + } + : input.customProperties; + if (customProperties) { + for (const key of Object.keys(input.customPropertyPatch ?? {})) + if (isEmptyCustomValue(customProperties[key])) + delete customProperties[key]; + } + if (customProperties !== undefined) updates.customProperties = updatedCustomProperties( this.config, original.customProperties, - input.customProperties, + customProperties, ); // The recurrence planner shifts civil dates. Convert existing instants @@ -546,11 +557,11 @@ export class TaskNotesTaskModel { if (plannedTask[role] === undefined) delete patched[this.config.fieldMapping[role]]; } - if (input.customProperties !== undefined) { + if (customProperties !== undefined) { for (const field of this.config.userFields.filter( (candidate) => !candidate.readOnly, )) { - const value = input.customProperties[field.key]; + const value = customProperties[field.key]; if (isEmptyCustomValue(value)) delete patched[field.key]; } } diff --git a/src/domain/view-preview.ts b/src/domain/view-preview.ts index d13ac99a..e67ef370 100644 --- a/src/domain/view-preview.ts +++ b/src/domain/view-preview.ts @@ -7,6 +7,11 @@ import { import type { TaskSummary } from "./task"; import type { EditableViewDraft } from "./view-document"; +type PreviewQuery = Pick< + EditableViewDraft, + "dialect" | "filter" | "computedProperties" | "sort" +>; + export interface ViewDraftPreview { kind: "live" | "current" | "unavailable"; count?: number; @@ -14,9 +19,15 @@ export interface ViewDraftPreview { } export function previewViewDraft( - draft: EditableViewDraft, + draft: PreviewQuery, tasks: readonly TaskSummary[], ): ViewDraftPreview { + if ( + draft.dialect === "obsidian-bases" && + draft.filter == null && + !draft.sort.length + ) + return { kind: "live", count: tasks.length, tasks: tasks.slice(0, 3) }; const matching = tasksForViewDraft(draft, tasks); if (!matching) return { kind: "unavailable", tasks: [] }; return { @@ -28,7 +39,7 @@ export function previewViewDraft( /** Evaluate an editable Obsidian Bases view against an in-memory task set. */ export function tasksForViewDraft( - draft: EditableViewDraft, + draft: PreviewQuery, tasks: readonly Value[], ): Value[] | null { if (draft.dialect !== "obsidian-bases") return null; @@ -53,7 +64,7 @@ export function tasksForViewDraft( } export function computedViewValues( - draft: EditableViewDraft, + draft: PreviewQuery, task: TaskSummary, ): Record { if (draft.dialect !== "obsidian-bases" || !draft.computedProperties.length) @@ -95,7 +106,7 @@ function taskProperties(task: TaskSummary): Record { function sortTasks( tasks: readonly Value[], - draft: EditableViewDraft, + draft: PreviewQuery, ): Value[] { if (!draft.sort.length) return [...tasks]; const rules = draft.sort.map((rule) => ({ diff --git a/src/test/next-entry-smoke-fixture.tsx b/src/test/next-entry-smoke-fixture.tsx index 1e052cc7..09483b6c 100644 --- a/src/test/next-entry-smoke-fixture.tsx +++ b/src/test/next-entry-smoke-fixture.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef, useState } from "react"; import { MdbaseError, + memoryWriteLedgerStore, toPlain, type DescribeResult, type JsonValue, @@ -65,6 +66,7 @@ export interface NextSmokeControl { declare global { interface Window { __TASKNOTES_NEXT_SMOKE__?: NextSmokeInput; + __TASKNOTES_OPEN_DEVICE__?: (page: Window) => Promise; __TASKNOTES_NEXT_SMOKE_CONTROL__?: NextSmokeControl; } } @@ -83,25 +85,26 @@ const views: AppBasesDescriptor[] = names.map((name, i) => ({ implementations: [], })); +type SmokeTaskType = { + implements: Array<{ + contract: string; + fields: Record; + binding: JsonValue; + }>; +}; + /** Local browser protocol stand-in, not native Core/auth/grant/READ evidence. * One original SDK client supplies CRUD and the synthetic Bases/catalog seam. * This module is reachable ONLY in the explicit e2e build on a loopback origin. */ -async function heldFixture(input: NextSmokeInput): Promise { +export function smokeDevice(input: NextSmokeInput) { const replicaOptions = { collection, confirmDelayMs: input.slowConfirmation ? null : 0, }; const replica = new MemoryReplica(replicaOptions); const generated = buildTaskNotesMdbaseResources({ profiles: ["core-lite"] }); - const type = (input.typeDefinition ?? generated.type) as { - implements: Array<{ - contract: string; - version: string; - fields: Record; - binding: JsonValue; - }>; - }; + const type = (input.typeDefinition ?? generated.type) as SmokeTaskType; replica.seedResource( "_types/task.md", serializeMarkdownDocument(type, "Synthetic task type"), @@ -111,8 +114,31 @@ async function heldFixture(input: NextSmokeInput): Promise { ...record, types: record.types ?? ["task"], }); + const ledger = memoryWriteLedgerStore(); + return { + replica, + ledger, + open: async (page: Window) => { + const repository = await heldFixture(input, type, replica, ledger, page); + if (page !== window) + page.addEventListener("pagehide", () => repository.dispose?.(), { + once: true, + }); + return repository; + }, + }; +} + +async function heldFixture( + input: NextSmokeInput, + type: SmokeTaskType, + replica: MemoryReplica, + ledger: ReturnType, + page: Window, +): Promise { const client = await connect({ connector: replica.connector(), + ledger, app: { name: "tasknotes-next-smoke", version: "fixture" }, reconnect: false, }); @@ -139,7 +165,7 @@ async function heldFixture(input: NextSmokeInput): Promise { errors: [], updates: [], confirm: () => { - replicaOptions.confirmDelayMs = 0; + replica.stallConfirmations(false); replica.confirmAll(); }, releaseReads: () => { @@ -157,7 +183,7 @@ async function heldFixture(input: NextSmokeInput): Promise { body: r.body, })), }; - window.__TASKNOTES_NEXT_SMOKE_CONTROL__ = control; + page.__TASKNOTES_NEXT_SMOKE_CONTROL__ = control; const available = () => { if (control.offline) throw new MdbaseError({ @@ -420,7 +446,10 @@ function FixtureInstallation() {

Local SDK protocol fixture; not native authorization or readiness.