Files
outline/app/components/Sidebar/Settings.tsx
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

96 lines
2.9 KiB
TypeScript

import { groupBy } from "es-toolkit/compat";
import { observer } from "mobx-react";
import { BackIcon } from "outline-icons";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import styled from "styled-components";
import Flex from "~/components/Flex";
import Scrollable from "~/components/Scrollable";
import useSettingsConfig from "~/hooks/useSettingsConfig";
import { useLocationSelector } from "~/hooks/useLocationSelector";
import useStores from "~/hooks/useStores";
import isCloudHosted from "~/utils/isCloudHosted";
import { settingsPath } from "~/utils/routeHelpers";
import Sidebar from "./Sidebar";
import Header from "./components/Header";
import HistoryNavigation from "./components/HistoryNavigation";
import Section from "./components/Section";
import SidebarButton from "./components/SidebarButton";
import SidebarLink from "./components/SidebarLink";
import Version from "./components/Version";
function SettingsSidebar() {
const { integrations } = useStores();
const { t } = useTranslation();
const history = useHistory();
const pathname = useLocationSelector((location) => location.pathname);
const configs = useSettingsConfig();
const groupedConfig = groupBy(
configs.filter((item) =>
item.group === t("Integrations") && item.pluginId
? integrations.findByService(item.pluginId)
: true
),
"group"
);
const returnToApp = useCallback(() => {
history.push("/home");
}, [history]);
return (
<Sidebar canCollapse={false}>
<SidebarButton
title={t("Return to App")}
image={<StyledBackIcon />}
onClick={returnToApp}
/>
<Flex auto column>
<Scrollable shadow>
{Object.keys(groupedConfig).map((header) => (
<Section key={header}>
<Header title={header}>
{groupedConfig[header].map((item) => (
<SidebarLink
key={item.path}
to={item.path}
onClickIntent={item.preload}
active={
item.path.startsWith(settingsPath("templates")) ||
item.path.startsWith(settingsPath("groups"))
? pathname.startsWith(item.path)
: undefined
}
icon={<item.icon />}
label={item.name}
/>
))}
</Header>
</Section>
))}
{!isCloudHosted && (
<Section>
<Header title={t("Installation")} />
<Version />
</Section>
)}
</Scrollable>
</Flex>
<HistoryNavigation />
</Sidebar>
);
}
const StyledBackIcon = styled(BackIcon)`
margin-inline-start: 4px;
[dir="rtl"] & {
transform: rotate(180deg);
}
`;
export default observer(SettingsSidebar);