Files
DeepTutor/docs-for-dev/perf/knowledge-settings-ui.md
Antonio-Faure 75636f0735 perf(web): improve knowledge-base and settings accessibility and payload (#3139)
* fix(web): refine knowledge and settings accessibility and layout

Name row controls from their visible titles, portal tooltip descriptions out of tablists, and make the knowledge tabs keyboard-complete. Also stack the KB master-detail on phones, add a section-scroll hint, demote the indexing diagnostic to its detail tab, and consolidate the knowledge type scale.

* perf(web): cut knowledge and settings payload

Serve raster engine marks through next/image, stop preloading the serif face on pages that do not use it, and prefetch settings routes only on hover or keyboard focus instead of on first paint.

* docs(perf): record knowledge and settings audit

Document the protocol, baseline and after medians, payload and accessibility results, limits, and reproduction commands, with mobile before/after screenshots.

* test(web): match the model row's visible accessible name

The row no longer overrides its name with a provider-first aria-label; select it by the model-first text a screen reader now reads, which also contains the visible default/task badge.

* fix(web): keep the MinerU download-type name in the locale catalog

Reuse the existing Download models and Type strings instead of introducing a new t() literal, so the strict i18n audit stays green.

* docs(perf): link the UI audit from the handbook index

The docs contract requires every guide under docs-for-dev to be reachable from README.md.

* docs(perf): record the isolated knowledge-detail LCP

Re-measured the detail route with the host pinned away from unrelated work; the 668 ms row was contention, while the isolated median is 568 ms and the stable repeats overlap the baseline.

---------

Co-authored-by: Antonio-Faure <209759495+Antonio-Faure@users.noreply.github.com>
2026-12-01 17:12:12 +08:00

265 lines
12 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Knowledge bases & settings — accessibility and payload pass
**Surface:** `/knowledge-bases`, `/knowledge-bases/[kbName]`, `/settings/general`,
`/settings/llm`, `/settings/knowledge`
**Branch:** `perf/knowledge-settings-ui-audit`
**Base:** `76dc7e2e2` (`dev`)
**Date:** 2026-11-30
This note records the baseline, the changes, and the after measurements for the
UI/performance pass on the Knowledge Center and Settings. All measurements are
lab measurements against deterministic fixtures, not production field data.
## Protocol
### Build and server
```bash
cd web
npm run build
npx next start --hostname 127.0.0.1 --port 3101
```
The build is the normal Webpack production build. `next start` prints the
existing `output: "standalone"` warning; it still serves the app. Do not run two
servers on 3101.
### Browser / run conditions
| Item | Value |
| --- | --- |
| Browser | Playwright Chromium `143.0.7499.4`, headless |
| Viewport | 1440 × 900, DPR 1, `en-US`, UTC, light colour scheme |
| Runs | 3 cold runs per page, median reported |
| Cache | New context per run + CDP `Network.clearBrowserCache` |
| Ready point | Page-specific content visible, `document.fonts.ready`, then 1.2 s settle |
| Idle window | 6 s; CPU/heap/DOM/polling sampled at the end |
| Network | Loopback, no CPU or network throttling |
| Console | 0 errors, 0 uncaught page errors on all 5 pages |
Fixtures: 8 KBs, 7 RAG providers, 9 raw files, 3 LLM profiles / 5 model rows,
MinerU as the active parser. All `/api/**` calls are intercepted and answered
from fixed JSON. The real backend is not used; payload sizes are smaller than a
real catalog, so API time/bytes are **understated**.
### Lighthouse
Lighthouse 12.8.2 ran once per page at 1440 × 900 desktop with the same fixtures
served by a local mock backend on `:8099` and a second production server on
`:3123`. Only `accessibility`, `best-practices` and `seo` were collected.
Lighthouse performance scores are not used.
### Host-load caveat for LCP/heap
The baseline was collected at load average ≈0.95. The first after run overlapped
other worktrees compiling/typechecking on the shared host (load average 2–5,
four vCPUs). The knowledge-detail row was then re-measured in isolation with the
measurement pinned to cores 1–3 and no builds/typechecks running; its stable
repeats (532–568 ms) overlap the baseline range. Transfer, JS, request counts
and Lighthouse audits are deterministic; **the other pages' LCP, heap and CPU
deltas are approximate and should not be read as precise
regression/improvement**. Every LCP remains well below 2.5 s. Re-run the same
protocol on an idle host before comparing the other absolute LCP numbers.
## Baseline vs after
### Page metrics (median of 3 cold runs, 1440 × 900)
| Page | LCP before | LCP after | CLS before | CLS after | Transfer before | Transfer after | JS before | JS after | Requests before | Requests after | DOM before | DOM after | Heap before | Heap after | Lighthouse a11y before | after |
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| `/knowledge-bases` | 440 ms | 384 ms | 0 | 0 | 693 KB | **551 KB** | 448 KB | 449 KB | 67 | **66** | 322 | 323 | 7.7 MB | 7.9 MB | 91 | **100** |
| `/knowledge-bases/quantum-notes` | 528 ms | 568 ms† | 0 | 0 | 649 KB | **587 KB** | 487 KB | 488 KB | 69 | **68** | 532 | 531 | 8.7 MB | 9.1 MB* | 88 | **100** |
| `/settings/general` | 724 ms | 720 ms | 0.002 | 0.002 | 655 KB | **460 KB** | 484 KB | **344 KB** | 78 | **41** | 433 | 432 | 7.3 MB | 8.1 MB* | 96 | **100** |
| `/settings/llm` | 704 ms | 672 ms | 0.002 | 0.002 | 657 KB | **464 KB** | 503 KB | **367 KB** | 82 | **44** | 404 | 401 | 7.2 MB | 8.4 MB* | 96 | **100** |
| `/settings/knowledge` | 688 ms | 360 ms | 0.002 | 0.002 | 640 KB | **442 KB** | 488 KB | **348 KB** | 78 | **38** | 466 | 467 | 8.5 MB | 8.8 MB* | 86 | **100** |
† KB detail was re-measured in isolation: production build, 1440 × 900,
browser cache cleared, 3 runs pinned to cores 1–3 with no builds/typechecks
running. Runs were 868 / 568 / 532 ms, median **568 ms**. The first run includes
browser/server warm-up; the stable repeats (532–568 ms) overlap the baseline
range (464–564 ms, median 528 ms). The earlier 668 ms was host contention, not a
render-blocking code change; no code change was made for it.
\* Approximate: the other four after rows overlapped unrelated host compilation
(see the host-load caveat). Each page's LCP is inside the 2.5 s budget; the
settings and KB-list wins are consistent with the payload reductions.
Best practices and SEO are **100** before and after on all five pages.
### Payload composition
| Item | Before | After |
| --- | --- | --- |
| KB-list images | 112 KB (6 raw icons, 200–1024 px sources) | **7 KB** (Next image optimizer, lazy below the fold) |
| KB-detail image | 27 KB | **2 KB** |
| Fonts on KB list / detail / LLM / knowledge | 66 KB (Geist + Lora preload) | **29 KB** (Geist only) |
| Fonts on settings general | 66 KB | 52 KB (Geist subsets) |
| Settings RSC prefetch | 18–19 requests / 21–23 KB | **1–4 requests / 1–5 KB** |
| Settings JS | 484–503 KB | **344–367 KB** |
| Settings requests | 78–82 | **38–44** |
The settings JS/request drop is the sidebar prefetch change: the page no
longer pulls every sibling section's route/chunks before the user chooses one.
The image drop is `next/image` for raster engine marks; the SVG marks stay
unoptimized. `preload: false` on Lora removes the serif font from pages that do
not render it.
### Accessibility
| Audit | Before | After |
| --- | --- | --- |
| Axe WCAG 2.1 A/AA violations | 2 / 2 / 1 / 1 / 3 | **0 / 0 / 0 / 0 / 0** |
| Lighthouse accessibility | 91 / 88 / 96 / 96 / 86 | **100 / 100 / 100 / 100 / 100** |
| Lighthouse best-practices | 100 | 100 |
| Lighthouse SEO | 100 | 100 |
| Keyboard tab stops without a visible focus ring | 0 | 0 |
Contrast: modern snow `--muted-foreground` moved from `#787774` (4.21–4.47:1)
to `#6b6965` (4.84:1 on `--muted`, 5.15:1 on the sidebar tint, 5.48:1 on white).
Dark and cream themes were left unchanged; axe found no contrast violations in
the dark theme either.
## Screenshots (390 × 844)
KB list before / after — full tab labels, stacked search row, larger metadata:
![KB list before](assets/kb-list-mobile-before.png)
![KB list after](assets/kb-list-mobile-after.png)
KB detail before / after — list stacks above a full-width preview, no lone
crumb separator, section-scroll hint, larger file tools:
![KB detail before](assets/kb-detail-mobile-before.png)
![KB detail after](assets/kb-detail-mobile-after.png)
Desktop 1440 × 900 evidence is available in the audit run; the mobile pair
shows every layout change made by this pass.
## What changed
### Accessibility
- `web/features/ui-layout/modern/modern.css` — darker snow-theme muted token.
- `web/components/settings/shared.tsx` — `SettingRow` now publishes its title id
through a context, so row controls can be named without duplicating copy.
- `web/components/settings/Toggle.tsx` — switches consume the row title as
`aria-labelledby`; an explicit `label` remains available for standalone use.
- `web/components/settings/MinerUEngineSettings.tsx` — explicit names for the
download-source, download-type and model-version selects.
- `web/components/settings/ModelsWorkspace.tsx` — removed the `aria-label` that
omitted the visible "Default model"/"Task model" text.
- `web/components/knowledge/KbDocumentList.tsx` — removed the path-only
`aria-label` that contradicted the visible file name.
- `web/shared/ui/Tooltip.tsx` — the screen-reader tooltip description is
portalled to `document.body` after hydration, so `role="tooltip"` is no
longer an invalid child of `role="tablist"`. `aria-describedby` still points
at the same id.
- `web/components/knowledge/KnowledgeHome.tsx` — roving `tabIndex`, arrow/Home/
End keys, `aria-controls` only on the active tab (the inactive panel is not
mounted).
### Payload
- `web/components/knowledge/KnowledgeEngineIcon.tsx` — `next/image` for raster
marks, with `unoptimized` for the two SVGs. Intrinsic width/height are kept.
- `web/app/layout.tsx` — Lora `preload: false`.
- `web/components/settings/SettingsNav.tsx` — nav links use `prefetch={false}`;
hover/focus calls `router.prefetch(href)` for intentional navigation.
### Mobile / hierarchy / type
- `web/components/knowledge/KbFilesTab.tsx` — file list stacks above the preview
under `md`; the collapsed rail stays side-by-side.
- `web/components/knowledge/KbDocumentList.tsx` — list is full-width and 42 %
height on mobile, 220 px rail on desktop; file-toolbar buttons are 32 × 32
(Lighthouse `target-size` passes at its 24 px threshold; 44 px was not used
because it would grow the compact header).
- `web/components/knowledge/KnowledgeBaseDetail.tsx` — section nav has a
right-edge scroll hint on mobile; the in-place crumb is hidden when the page
bar is absent; `KbIndexingRun` only renders on "Index versions"; detail title
uses the layout title token instead of a hard-coded serif.
- `web/components/knowledge/KbFilePreview.tsx`, `KbStatusBadge.tsx`,
`KnowledgeHome.tsx`, `KbDocumentList.tsx` — knowledge type scale consolidated
to 11/12/13/14/18 px (10/11.5/12.5/13.5 removed). File metadata stays at 11 px
so the 220 px rail does not truncate dates.
### Tests added
- `web/tests/settings-row-a11y.spec.tsx` — switch named by its `SettingRow`;
tooltip description not inside a tablist.
- `web/tests/knowledge-home-tabs.spec.tsx` — roving focus, ArrowRight, Home, End,
and `aria-controls`.
- `web/tests/e2e/knowledge-settings-a11y.audit.ts` — Playwright audit for all four
MinerU switches, three selects, tab keyboard selection and the 390 px
master–detail layout / 32 px file tools.
## Verification
```bash
cd web
npm run typecheck
npm run test:node
npm run test:unit -- tests/settings-row-a11y.spec.tsx tests/knowledge-home-tabs.spec.tsx
npm run lint
npm run build
npm run perf:check
# production server on 3101, then:
WEB_BASE_URL=http://127.0.0.1:3101 npx playwright test \
tests/e2e/knowledge-settings-a11y.audit.ts --project=ui-audit --workers=1
```
`npm run perf:check` after the change:
```
OK /chat 1099KB / budget 1100KB
OK /settings 127KB / budget 840KB
OK /knowledge-bases 487KB / budget 550KB
OK /co-writer 468KB / budget 470KB
OK /co-writer/[docId] 512KB / budget 515KB
OK /learning/reading/... 1367KB / budget 1370KB
OK /learning/mastery/... 912KB / budget 1090KB
OK root-app-shell 343KB / budget 390KB
```
Shared budgets remain the constraint: `/chat` is at 1099/1100 KB and co-writer
at 468/470 KB. The changes add only local settings/knowledge code; no shared
dependency was added.
## Reproduction
The measurement harness lives outside the repository (so it cannot drift with
app code): `/tmp/opencode/kb-audit/`.
```bash
# terminal 1
cd web && npm run build
npx next start --hostname 127.0.0.1 --port 3101
# terminal 2
cd /tmp/opencode/kb-audit
RUNS=3 IDLE_MS=6000 node measure.cjs after.json
node screens.cjs # 1440 / 820 / 390 screenshots
node a11y-detail.cjs # axe + focus/tab checks
```
For Lighthouse, serve the same fixtures on `:8099` and start a second production
server with `DEEPTUTOR_API_BASE_URL=http://127.0.0.1:8099` on `:3123`, then run
Lighthouse with a desktop 1440 × 900 config. The harness mock covers
`/api/auth/status`, `/api/settings*`, `/api/modules`, `/api/system/status`,
`/api/knowledge-bases/*`, `/api/sessions` and `/workspaces/index`; every other
`/api` request returns an empty JSON object so an unrelated endpoint cannot
change the rendered screens.
## Limits / scope
- No functional, API, auth or SSE/WebSocket change.
- The live indexing path was idle; the next verification should exercise an
active reindex and confirm progress WebSocket behaviour is unchanged.
- Type-scale consolidation covers the knowledge surfaces only; settings keeps
its existing scale to keep the diff reviewable.
- Mobile section tabs remain horizontally scrollable; a right-edge gradient plus
chevron now signals more tabs. They were not converted to a menu to avoid a
flow change.
- LCP/heap after values are host-load-approximate as described above.