Repository navigation
Commit 2efcedd
perf(console): the chat UI, the auth pages and qrcode leave the first load (#38384)
<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
Fixes #37572
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoAoNwrZVJoUEFfvMURpRPKJ)_
Part of #37444
Clause-②: no (load order only)
Metadata-protocol: none
## 维护者速读
- 用户能看到什么变化:控制台每个页面在画出来之前要下载的脚本少了约 326
KB(压缩后),聊天助手改为第一次打开聊天面板时才下载,登录等账号页面改为打开该页时才下载,二维码改为第一次显示时才下载;界面和数据都不变。
- 为什么做:属于首屏加载提速专项;聊天界面因打包分组漏列两个文件,又回到了每个页面的首次加载里,这次补上,并加了守卫,再漏会直接报错。
-
出错会怎样:最坏情况是访客打开登录页、第一次打开聊天面板或显示两步验证二维码时多等片刻,或看到加载失败的提示;不涉及保存的数据,可以直接撤回这次合并。
- 要你做什么:无。
## What changes
The chunks every Console page fetches before it can draw drop from
2,226,792 to 1,893,160 bytes gzipped (147 to 134 eager chunks), measured
on production builds of `main` at `eef1cbfe4` and of this branch at
`686c9993`. Three cuts, as amendment 7243947617 on the card lists them:
1. **The chat UI leaves the first load again**
(`ui/apps/console/vite.config.ts`).
`packages/plugin-chatbot/src/core.ts` re-exports `hitlContinuation` and
`chat/questionSkip`, and the `plugin-chatbot-core` chunk group did not
list them. They landed in `plugin-chatbot`, which the eager core chunk
then imported statically, and that pulled in `plugin-chatbot` (236,909
gz) and `plugin-markdown` (69,180 gz) on every page. The group lists
both now.
2. **The 9 public auth pages and the 4 dev harness pages load with their
routes** (`ui/apps/console/src/App.tsx`). Each page now uses `lazy()`.
The dev pages sit behind `ProtectedRoute` and get their own Suspense
boundary, as `DevRowActions` already did. The auth pages get no boundary
of their own. They suspend into `ConsoleShell`'s boundary, which also
holds `NativeShellRouting`, so the mobile shell's `ready()` still waits
until `/login` is on screen (see Acceptance notes).
3. **`qrcode` is imported on demand** at its two call sites: `TotpQr` in
`RemediationOverlay.tsx` and `QrcodeBlock` in `ActionResultDialog.tsx`.
If the import fails, the message goes to the error slot that an encoding
error already used.
**Guard.** `ui/scripts/check-eager-closure-budget.mjs` gains a sixth
half, `evaluateLazyChatChunks`. It fails when a `plugin-chatbot` or
`plugin-markdown` chunk is in the eager closure, whatever the aggregate
says. It returns error when the report has no files, or when its
counter-probe finds no module of either package in a chunk of that name,
so a renamed chunk cannot pass by default. Unit tests cover pass, fail
for each chunk, the counter-probe, an unreadable report, and `main`
going from exit 0 to 1. A static case also checks that every `export ...
from` in `core.ts` is matched by the group regex parsed out of
`vite.config.ts`.
**Re-pin.** I re-pinned by the gate's documented formula at the measured
head, as the seat ruled. The ceiling is `MAX_EAGER_CLOSURE_GZIP_BYTES` =
1,893,160 + 711,680 / 2 = **2,249,000** (it was 2,407,237). `BASELINE` =
1,893,160 / 134 / 2653 at `686c9993`, with `squashMerge` null until a
back-fill. The four per-chunk ceilings did not move. Changeset: patch
for `@object-ui/app-shell`, `@object-ui/console` and
`@objectstack/console`.
## Tests
Every reading in this section was taken at head `809cfb890`. Commit
`809cfb890` changes only the gate script and its test, and
`vite.config.ts` does not import that script, so no bundler input
differs from `686c9993`, where the bundle was built.
- Eager closure gate on the head build: `node
scripts/check-eager-closure-budget.mjs` (in `ui`) exits 0. Every half is
✅, including "Chat chunks stay lazy". The same gate on the `main` build
exits 1 on that half.
- Ablation of cut 1, recorded earlier in this round (literal anchor,
blob hashes checked, restore verified equal to HEAD): the unit static
case goes red naming `./hitlContinuation` and `./chat/questionSkip`. The
rebuilt bundle reads 2,201,929 gz in 148 eager chunks. The gate exits 1
from the chat half alone, while the aggregate half stays ✅ (2150.3 KB
under the 2196.3 KB budget). Without the new half, the gate would not
have caught this regression.
- `pnpm --dir ui exec vitest run scripts/`: 172 files passed, 2 skipped;
5159 tests passed, 2 skipped.
- Console: `App.docsPortalLazy`, `App.nativeShellMode-29039` and
`App.nativeShellOpenSet-29330`: 2 of 3 files passed on the first run, 1
test failed (see Acceptance notes, "a timing-dependent assertion").
Re-run of `App.nativeShellMode-29039` 4 times on an idle box: 17/17
each, then 3 more times under synthetic CPU load: passed each time.
- app-shell `RemediationOverlay*` and `ActionResultDialog` tests: 7/7
files, 48/48 tests.
- `type-check` exits 0 for `@object-ui/console` and for
`@object-ui/app-shell` (its script also runs `tsconfig.test.json`).
- Not run locally, declared: the full `@object-ui/app-shell` and
`@object-ui/console` suites (CI `Test UI` runs them).
<details><summary>Derived gates (dispatch-gates --commands, 47 families,
at 809cfb8)</summary>
`node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack
--ran` with the exit-coded record: "47 derived famil(ies) accounted for
— 45 run, 2 NOT-MEASURED". 45 exited 0. NOT MEASURED: `pnpm
check:dual-build-cjs-loads` (exit 3, PREREQUISITE NOT MET: the
`@objectstack/*` packages are not built in this worktree; `Build Core`
builds them in CI), and `pnpm check:type-check-debt` (its re-measure
needs a full-repo package build; CI `Lint & Repo Gates` runs it).
`overlap-check.mjs --branch=claude/project-thread-ciejge`: "VERDICT
clean exit 0", merges cleanly onto `origin/main` `61cde6dc7`.
</details>
## Acceptance notes
- **Mobile shell ready signal.** My first version of cut 2 gave each
auth route its own Suspense boundary. `App.nativeShellMode-29039` and
`App.nativeShellOpenSet-29330` then caught `ready()` being posted over
the loading fallback (`ready:nothing`) instead of the login page.
Removing those boundaries fixes it. The native shell drops its cover
only once the first route is on screen, as before.
- **A file outside the amendment's list.** `App.docsPortalLazy.test.tsx`
used `LoginPage` as its live positive control for an eager import. Cut 2
makes that page lazy, so the control moves to `FormPage`, which is still
static. This is the same move objectui#13410 made when
`SharedRecordPage` went lazy. The test file is not on the amendment's
file list. It is in this PR because cut 2 made its assertion false. It
is in commit `686c9993`.
- **Out of scope, not fixed here.** On a two-factor-armed boot
(`OS_AUTH_TWO_FACTOR=true`), the "Enable Two-Factor Auth" button does
not render on the user's own record in Setup (Users, Security tab). This
happens on the `main` build and on this branch alike. The browser
console says: `[ActionEngine] action "enable_two_factor" hidden: its
visible predicate threw — CEL predicate failed to evaluate:
(has(record.id) && record.id == ctx.user.id &&
has(record.two_factor_enabled) && record.two_factor_enabled != true) &&
features.twoFactor == true`. The record shows "Two-Factor Enabled: No",
and `/api/v1/auth/config` reports `features.twoFactor: true`. It is in
the report for the seat to file. Because of it, the QR reading below
goes through the other call site, the MFA remediation overlay.
- The Console has no assistant button on the open framework, because
discovery reports `services.ai` unavailable and `GET /api/v1/ai/agents`
returns an empty list. For the chat-panel reading, the browser stubs
that one endpoint with a single agent so the button and the drawer
render. What the reading measures is which chunks the browser fetches.
It does not measure a reply.
- **A timing-dependent assertion, found at this head and NOT fixed in
this PR.** The first local run of `App.nativeShellMode-29039` failed
once in "posts ready once, after the first route rendered": `expected []
to deeply equal [ 'ready:login-page', 'route:/login' ]`. With the auth
pages lazy, the first route commits after a chunk resolves, and
`ready()` and `routeChanged` run in that commit's passive effects. These
effects can land after `findByTestId` returns, so the synchronous
`expect(events)` right after it can read an empty list. On `main` the
page was eager, so the first route committed inside `render`'s `act`
(inferred from the code, not measured). Measured: 1 failure in 9 runs,
on a cold and loaded box. The fix is five `waitFor` wraps in that file
and in `App.nativeShellOpenSet-29330`. Both files are outside the
amendment's file list, so the fix is left to the seat to add to the file
list, not pushed here.
## Verification
Read first, by risk:
1. `ui/apps/console/src/App.tsx`: the comment above the lazy pages and
the 9 auth routes without their own boundary. A boundary added back
there would bring back the early `ready()`.
2. `ui/scripts/check-eager-closure-budget.mjs`:
`evaluateLazyChatChunks`, and the `chat-lazy` entry in `main`'s fold.
3. `ui/packages/app-shell/src/views/ActionResultDialog.tsx`: the
`import('qrcode')` path that writes to the error slot.
Two-minute check: run `pnpm --filter @object-ui/console build` and then,
in `ui`, `node scripts/check-eager-closure-budget.mjs`. Expect "✅ Chat
chunks stay lazy" and about 1848.8 KB eager against a 2196.3 KB budget.
## Readings
<details><summary>Eager closure before and after (production builds,
same container, same instrument)</summary>
Both builds were measured with `emitEagerClosureReport`
(`dist/eager-closure.json`). Control: `main` at `eef1cbfe4`. Head:
`686c9993`. Commit `809cfb890` changes only the gate script and its
test.
| chunk | `eef1cbfe4` | `686c9993` | delta |
|---|---:|---:|---:|
| `plugin-chatbot` | 236,909 | not eager | -236,909 |
| `plugin-markdown` | 69,180 | not eager | -69,180 |
| `index` | 135,874 | 117,803 | -18,071 |
| `browser` (qrcode) | 8,804 | not eager | -8,804 |
| everything else | 1,776,025 | 1,775,357 | -668 |
| **aggregate (gz)** | **2,226,792** (147 of 2633) | **1,893,160** (134
of 2653) | **-333,632** |
The per-chunk rows are unchanged: `vendor-objectstack` -392, `framework`
-18, `ui-components` +583, `i18n-locale-en` 0.
Earlier readings, kept as recorded: at `483eaa34`, 1,893,147 in 134 of
2653. With cut 1 ablated, 2,201,929 in 148 of 2653.
</details>
<details><summary>Gate at head: exit 0</summary>
```
✅ Console eager closure is 1848.8 KB gzipped across 134 of 2653 chunks (budget: 2196.3 KB, headroom: 347.5 KB).
✅ Per-chunk eager budgets (4 chunks weighed)
✅ Chunk membership: 5 budgeted package(s) each landed exactly where declared
✅ Ceiling sensitivity (5 ceilings): aggregate headroom 347.5 KB = 0.50x the 695.0 KB regression
✅ Chat chunks stay lazy: `plugin-chatbot` and `plugin-markdown` hold modules in this build and none of them is in the eager closure.
```
The ablation build (cut 1 reverted) gives:
```
✅ Console eager closure is 2150.3 KB gzipped across 148 of 2653 chunks (budget: 2196.3 KB, headroom: 46.0 KB).
❌ Chat chunks are in the EAGER closure, so every console page downloads the chat UI before it draws: `plugin-chatbot` 231.4 KB, `plugin-markdown` 67.6 KB.
```
The gate exits 1.
</details>
<details><summary>Browser readings: real Chromium 1243 through
Playwright 1.63, production builds, HTTP/2 TLS front</summary>
Setup: `objectstack start` with `NODE_ENV=production`,
`OS_AUTH_TWO_FACTOR=true` and `OS_TRUSTED_ORIGINS` set to the front, the
showcase app and a SQLite file database. The main and PR dists were
served in turn by the same server behind the same HTTP/2 front. Each
check used a fresh browser context, and every document was served over
`h2`.
| reading | `main` build | PR build |
|---|---|---|
| signed-out `/login` renders the e-mail and password inputs | yes | yes
|
| `/login` fetches a `LoginPage-*.js` chunk | no (inlined in `index`) |
yes, `LoginPage-TuUOOWNS.js` |
| chat chunks fetched by `/login` | `plugin-markdown`, `plugin-chatbot`
| none |
| chat chunks fetched by a signed-in page before the chat opens |
`plugin-markdown`, `plugin-chatbot` | none |
| chat chunks fetched by the first click on Ask AI | none (already
loaded) | `plugin-markdown-z1wyxXLS.js`, `plugin-chatbot-eTgo7l4P.js` |
| the chat drawer opens with its composer | yes | yes |
| 2FA QR: `qrcode` chunk fetched before enrolment | (eager) | none |
| 2FA QR: fetched on submit | | `browser-jSiDnjdN.js` (the `qrcode`
chunk, not eager) |
| 2FA QR: canvas drawn | | 184x184, 16,206 dark and 17,650 light pixels,
no error text |
The QR was read on the MFA remediation overlay (`TotpQr`) for a second
account, with `auth.mfa_required` set to `everyone` and a grace period
of 0. The setting was restored to `off` afterwards. Notes on why: the
record-page "Enable Two-Factor Auth" button does not render on either
build (Acceptance notes), and the agent catalog is stubbed for the chat
reading because the open framework has no AI service.
</details>
<details><summary>LCP medians by the #37444 method</summary>
Method: production builds, HTTP/2 TLS front, Lighthouse 13.6.0
`desktop-config` (simulated throttling, storage reset on), signed in
through the Console login form, Chromium 1243 headless. I ran the arms
back to back in blocks main-1, pr-1, pr-2, main-2 of 5 runs per page
each, so each arm has 10 runs. Every document and script was served over
`h2`, and no run recorded a runtime error.
| page | main median LCP (ms) | PR median LCP (ms) | delta |
|---|---:|---:|---:|
| home (`/_console/home`, landing on the showcase capability map) |
2,214 | 2,068 | -147 (-6.6%) |
| list (`/apps/com.example.showcase/showcase_task`) | 2,734 | 2,562 |
-172 (-6.3%) |
| record (`.../showcase_task/record/GYPAOUBLX6JfK5c_`) | 2,510 | 2,310 |
-200 (-7.9%) |
Home caveat. `/_console/home` redirects to the last app opened. In block
main-1 it landed on the Setup dashboard, because the browser checks
before it had last opened Setup. Those 5 runs measure a different page
(2,473 to 2,707). They are excluded from the home row and kept in the
raw data. To give main 10 runs on the same landing page, I appended a
block main-3 of 5 home runs; it ran right after main-2, not interleaved
with a PR block. The unfiltered home medians are main 2,378 and PR
2,068.
Scripts fetched per load: home 180 on main and 167 on the PR, list 285
and 274, record 217 and 206.
Runs (ms):
- main home: 2.1=2277 2.2=2283 2.3=2219 2.4=2233 2.5=2227 3.1=2208
3.2=2209 3.3=2189 3.4=2192 3.5=2201 (main-1, on the Setup dashboard:
2661 2707 2703 2473 2662)
- pr home: 1.1=2140 1.2=2099 1.3=2007 1.4=2035 1.5=2062 2.1=2060
2.2=2073 2.3=2102 2.4=2000 2.5=2082
- main list: 2751 2668 2771 2731 2672 2736 2740 2663 2834 2706
- pr list: 2540 2607 2634 2559 2564 2424 2585 2557 2630 2514
- main record: 2510 2518 2485 2510 2536 2604 2478 2489 2511 2490
- pr record: 2351 2311 2303 2276 2288 2385 2310 2331 2301 2357
These are shared-box readings. The runs held the verify lock, which
excludes other locked runs but not other unlocked work.
</details>
<details><summary>Appended after the session restart: the gate re-read
at head 809cfb8</summary>
Commit `809cfb890` changes only
`ui/scripts/check-eager-closure-budget.mjs` and its test (`git diff
--stat 686c999 809cfb8`: 2 files). `ui/apps/console/vite.config.ts`
does not import that script, so no bundler input differs from
`686c9993`, and the eager closure was not rebuilt. The
`dist/eager-closure.json` on disk is byte-identical (`cmp`) to the
`686c9993` reading recorded above. `node
scripts/check-eager-closure-budget.mjs` at committed head `809cfb890`
exits 0, and its output is byte-identical (`diff`) to the "Gate at head"
block above: 1848.8 KB across 134 of 2653 chunks against a 2196.3 KB
budget (2,249,000 bytes), and "Chat chunks stay lazy". No recorded
number changes.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 23c311e commit 2efcedd
10 files changed
Lines changed: 421 additions & 70 deletions
File tree
- .changeset
- ui
- apps/console
- src
- __tests__
- packages/app-shell/src
- console
- views
- scripts
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 21 | | |
26 | 22 | | |
27 | 23 | | |
| |||
59 | 55 | | |
60 | 56 | | |
61 | 57 | | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | 58 | | |
72 | 59 | | |
73 | 60 | | |
| |||
107 | 94 | | |
108 | 95 | | |
109 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
110 | 124 | | |
111 | 125 | | |
112 | 126 | | |
| |||
471 | 485 | | |
472 | 486 | | |
473 | 487 | | |
474 | | - | |
| 488 | + | |
475 | 489 | | |
476 | 490 | | |
477 | 491 | | |
478 | 492 | | |
479 | 493 | | |
480 | | - | |
| 494 | + | |
481 | 495 | | |
482 | 496 | | |
483 | 497 | | |
484 | 498 | | |
485 | 499 | | |
486 | | - | |
| 500 | + | |
487 | 501 | | |
488 | 502 | | |
489 | 503 | | |
490 | 504 | | |
491 | 505 | | |
492 | | - | |
| 506 | + | |
493 | 507 | | |
494 | 508 | | |
495 | 509 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
131 | 132 | | |
132 | 133 | | |
133 | 134 | | |
134 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 142 | + | |
142 | 143 | | |
143 | 144 | | |
144 | 145 | | |
| |||
166 | 167 | | |
167 | 168 | | |
168 | 169 | | |
169 | | - | |
| 170 | + | |
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
204 | 208 | | |
205 | 209 | | |
206 | 210 | | |
| |||
216 | 220 | | |
217 | 221 | | |
218 | 222 | | |
219 | | - | |
| 223 | + | |
220 | 224 | | |
221 | 225 | | |
222 | 226 | | |
| |||
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
229 | | - | |
| 233 | + | |
230 | 234 | | |
231 | 235 | | |
232 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
189 | 192 | | |
190 | | - | |
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
| |||
234 | 236 | | |
235 | 237 | | |
236 | 238 | | |
| 239 | + | |
237 | 240 | | |
238 | | - | |
239 | 241 | | |
240 | 242 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1593 | 1593 | | |
1594 | 1594 | | |
1595 | 1595 | | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
1596 | 1601 | | |
1597 | 1602 | | |
1598 | | - | |
| 1603 | + | |
1599 | 1604 | | |
1600 | 1605 | | |
1601 | 1606 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
| |||
239 | 238 | | |
240 | 239 | | |
241 | 240 | | |
242 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
243 | 247 | | |
244 | 248 | | |
245 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
| |||
421 | 420 | | |
422 | 421 | | |
423 | 422 | | |
424 | | - | |
425 | | - | |
426 | | - | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
427 | 432 | | |
428 | 433 | | |
429 | 434 | | |
| |||
0 commit comments