mirror of
https://github.com/outline/outline.git
synced 2026-11-28 08:14:58 +03:00
* 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
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { autorun } from "mobx";
|
|
import { SidebarExpansionState } from "./SidebarExpansionContext";
|
|
|
|
describe("SidebarExpansionState", () => {
|
|
it("should only notify observers of the node that changed", () => {
|
|
const state = new SidebarExpansionState();
|
|
let runs = 0;
|
|
const dispose = autorun(() => {
|
|
state.isExpanded("a");
|
|
runs++;
|
|
});
|
|
|
|
state.expand("b");
|
|
state.expandPath(["c", "d"]);
|
|
expect(runs).toBe(1);
|
|
|
|
state.expand("a");
|
|
expect(runs).toBe(2);
|
|
|
|
state.collapse("a");
|
|
expect(state.isExpanded("a")).toBe(false);
|
|
expect(runs).toBe(3);
|
|
|
|
dispose();
|
|
});
|
|
|
|
it("should expand and collapse descendants", () => {
|
|
const state = new SidebarExpansionState();
|
|
const node = {
|
|
id: "a",
|
|
title: "A",
|
|
url: "/doc/a",
|
|
children: [{ id: "b", title: "B", url: "/doc/b", children: [] }],
|
|
};
|
|
|
|
state.expandDescendants(node);
|
|
expect(state.isExpanded("a")).toBe(true);
|
|
expect(state.isExpanded("b")).toBe(true);
|
|
|
|
state.collapseDescendants(node);
|
|
expect(state.isExpanded("a")).toBe(false);
|
|
expect(state.isExpanded("b")).toBe(false);
|
|
});
|
|
});
|