# Page loading performance

The shared shell loads on every application page. Startup code, repeated catalog work and provider selection rendering are optimized without changing authentication, route history or model capabilities.

| Measure | Baseline | Now |
| --- | --- | --- |
| Initial JavaScript, gzip | 832419 bytes in 33 files | 618268 bytes |
| Warm catalog, five-sample median, same machine | 1248.779 ms | 24.012 ms |
| Credential enumerations per catalog request | 234 | 1 |
| Rows redrawn on a provider selection | 239 | 2 |

Not end-to-end click timings. In the baseline all fourteen DiceBear styles entered the initial graph (two avatar chunks, about 270 KB gzip), the native Provider list request took 1138 ms, and a Python profile counted 1.318 s of cumulative enumeration. Session-long resource counts include three-second polling and are not cold-start timings.

## Design

| Area | Rule |
| --- | --- |
| Avatars | Optional styles load by explicit [dynamic import](https://nextjs.org/docs/app/guides/lazy-loading) ([React lazy loading](https://react.dev/reference/react/lazy)); the default `shapes` style stays synchronous. In-flight loads are shared; a failed import can retry. Results arriving after unmount or a configuration change are ignored. |
| First-load imports | The sidebar renders before the app shell, so every module it reaches through static imports is in the first load. Those modules import single files, not barrels or renderers: `escHtml` from `dom/esc-html`, not the Markdown renderer (marked and KaTeX, about 93 KB gzip); `Avatar` from `avatar/avatar`, not the avatar barrel with the picker; the desktop bridge accessor from `bridge/bridge-api`, not the whole bridge. The rest arrives with the app shell. |
| SVG cache | Module-level reuse, bounded (128 entries, 512K characters). Upload and letter modes generate no DiceBear SVG. |
| Provider rows | [React memo](https://react.dev/reference/react/memo) with stable callbacks; a selection change does not regenerate unchanged icons. |
| Catalog | One snapshot per request (`credential_status_snapshot`): which providers hold credentials, how the catalogue's providers are grouped into companies, and the config file's path, each settled once instead of once per provider. A provider with no credential row and no key variable set is not configured without resolving a key. The config file is still checked on every read. Nothing crosses requests or becomes an authentication decision cache. |
| Change notices | The query client follows each Worker topic once for all readers (the inbox included), and applies the notices of one moment together: the socket opening, which tells every topic and then everything, reads each query on screen once, and no read is cancelled to send the same read again. |
| Settings reads | A successful read seeds the first Provider catalog view only while fresh. Mutations invalidate it. |
| Settings opening | The open tab reads at once; every other tab's reads run at idle after the first paint, a few per idle slice (`runInIdleSlices`). About twenty `fetch` calls in the opening task held its paint by 21 ms at 4× CPU throttle. |
| Layout reads | A component that measures on mount waits for its `ResizeObserver`'s first report (after layout, before paint) instead of reading rects in a layout effect, which laid the new page out an extra time mid-commit. The choice groove's sliding face does this. Formatters with options are built once per module, not per call. |

## Interaction budget

The budget for a click and the rules that keep it are in [Performance architecture](https://openprogram.io/docs/reference/design/ui/performance-architecture.html).

## Waiting without words

No page, panel or card says that it is loading, retrying or could not read something, and there is no error page or Retry button for a read the app makes by itself. A wait is made short instead of being narrated.

| Case | Rule |
| --- | --- |
| Not there yet | The spot stays empty in its final size; nothing jumps when the data lands. An empty state ("No runs yet") appears only once an answer has arrived and is empty. |
| Seen before | The last answer is drawn on the first frame and refreshed in the background: query data is kept 30 minutes, and reads outside TanStack Query keep their last answer for the page's life. |
| First visit | Every shell route and the eleven lazily loaded tab panes are fetched within a second of the first paint; each nav page's first read starts at idle and on hover of its nav item. |
| A read fails | The last data stays; the read is retried with backoff (1 s doubling to 30 s) and logged with `console.warn`. Failures of reads the page sent by itself raise no toast. |
| A permanent answer | A 4xx, "not found" or "deleted" reply ends the retries and the page acts on it: a detail page whose item is gone returns to its list, a conversation that no longer exists closes, a section the server refuses is not drawn. One failing source does not hold back the others. |
| Stays on screen | The outcome of what the user just did (a save or a key refused, an optimistic change rejected, a folder they opened that could not be read), the state of the content itself (an archive that is corrupt, an image that cannot be decoded), and a sign-in that has expired. |
| Server data | A reply body is `unknown` until checked (`apps/web/lib/net/json-unknown.d.ts`); an error field that may be a sentence, a list or an object becomes text through `errorDetailText`. Rendering an unchecked object took whole windows down. |

Measured on the installed default App before the change, a fast machine: Loading text flashed on first visits to Agents, MCP, Plugins, Applications, History, Scheduler, Programs, Projects, Memory and five Settings tabs (10 to 500 ms), at cold start (about 850 ms in) and on opening a conversation (about 130 ms).

After the change, the same walk (cold start, 25 pages, three conversations and each of their panel tabs) shows no loading or failure text and no page error.

## Must stay true

- Unsupported providers stay unsupported. Local provider identity, aliases, account presence, CLI fallbacks and env or cloud credential semantics do not change.
- Metrics never expose credential values.
- Cache expiry, failed requests and loading placeholders never show another provider as the selected route.
- Upload, letter, all generated styles, Thumbs background and SVG ID isolation remain.

**Acceptance**

- Public Avatar import loads only the default style; chosen styles load once; all fourteen stay selectable.
- Identical avatars reuse markup within the bounded cache.
- Catalog list tests prove one enumeration per request and immediate changes on the next request.
- Selection updates render only affected rows; warm catalog revisits show cached rows at once.
- Production entry bytes and same-machine catalog timings are compared with the baseline.
- Chat, Agents, Abilities, General and Provider navigation are checked in the installed default App.
