# 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 | 496156 bytes |
| Warm catalog, five-sample median, same machine | 1248.779 ms | 267.607 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. |
| 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 credential-presence snapshot per request. It never crosses requests or becomes an authentication decision cache. |
| Settings reads | A successful read seeds the first Provider catalog view only while fresh. Mutations invalidate it. |

## 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.
