Files
outline/app/stores/DocumentsStore.test.ts
T
Tom Moor ef6e51401b perf: Reduce main-thread cost of opening a document from the sidebar (#14033)
* perf: Read active models lazily in ActionContextProvider

The root provider read the active document and models during render, so
every navigation rebuilt the context and re-rendered all consumers. These
values are now getters, and overrides are merged without evaluating them.

* perf: Skip urlId scan in Store.get for UUIDs

When an id was not loaded, get() searched every item by urlId, so each
sidebar row observed the whole store. A UUID cannot end with a urlId, so
the search is skipped for UUIDs.

* perf: Stop sidebar rows re-rendering on navigation

- Track expanded nodes in an observable map, as ObservableSet.has tracks
  the whole set.
- Do not rebuild the document tree rows when the active document changes.
- Auto-expand the active path in a reaction instead of reading the active
  document during render.
- Compute active state per row, and keep row props stable.

* perf: Add useLocationSelector for persistent components

useLocation re-renders on every navigation. The new hook re-renders only
when the selected value changes, and is used where components stay mounted
across navigation. AuthenticatedLayout now keeps its portal element in
state, as it no longer re-renders after mount.

* chore: Send Document-Policy js-profiling header in development

* docs: Add render performance guidance to AGENTS.md

* fix: Check document or collection star exclusively for active state

* fix: Read location from each action context provider's own history

Nested providers inherited the root location getter, so menus inside a
split view pane read the browser route instead of the pane's route.

* fix: Expand starred collection when the active document changes
2026-10-11 15:17:01 -04:00

60 lines
1.8 KiB
TypeScript

/* oxlint-disable */
import stores from "~/stores";
describe("DocumentsStore", () => {
describe("get", () => {
it("should return a document by id or by the urlId in a slug", () => {
const doc = stores.documents.add({
id: "5f1c2a7e-8a7b-4c3d-9e2f-1a2b3c4d5e6f",
urlId: "AbCdEf1234",
title: "Slug",
});
expect(stores.documents.get(doc.id)).toBe(doc);
expect(stores.documents.get("slug-AbCdEf1234")).toBe(doc);
expect(stores.documents.get("AbCdEf1234")).toBe(doc);
});
it("should not match a urlId at the end of an unknown UUID", () => {
stores.documents.add({
id: "0b9e7c52-3f0e-4a8f-b1a5-2d7f7d9c1e3a",
urlId: "e056e0bb98",
title: "Suffix",
});
expect(
stores.documents.get("9b587fc1-01de-4f4a-aa79-07e056e0bb98")
).toBeUndefined();
});
});
describe("deleted", () => {
test("should filter by the user that deleted the document", () => {
const deleter = stores.users.add({
id: "22222222-2222-2222-2222-222222222222",
name: "Deleter",
});
const other = stores.users.add({
id: "33333333-3333-3333-3333-333333333333",
name: "Other",
});
const mine = stores.documents.add({
id: "11111111-1111-1111-1111-111111111111",
title: "Deleted by me",
deletedAt: "2026-08-18T00:00:00.000Z",
deletedBy: deleter,
});
stores.documents.add({
id: "44444444-4444-4444-4444-444444444444",
title: "Deleted by someone else",
deletedAt: "2026-08-18T00:00:00.000Z",
deletedBy: other,
});
const results = stores.documents.deleted({ userId: deleter.id });
expect(results.map((doc) => doc.id)).toEqual([mine.id]);
});
});
});