Skip to content

Commit 2efcedd

Browse files
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
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/console': patch
4+
'@objectstack/console': patch
5+
---
6+
7+
perf(console): the chat UI, the sign-in pages and the QR encoder leave the Console's first load
8+
9+
Clause-②: no (load order only)
10+
Metadata-protocol: none
11+
12+
The chunks every Console page fetches before it can draw are about 326 KB smaller gzipped. Nothing a user sees or saves changes; some code now loads when it is first needed instead of on every page.
13+
14+
- **`@object-ui/console`, `@objectstack/console`.** The chat UI (the `plugin-chatbot` chunk and the markdown highlighter behind it) had come back into every first load, because two helpers the chat package's side-effect-free entry re-exports were missing from the chunk group that keeps that entry apart from the chat UI. They are listed now, so the chat UI loads when a chat panel first opens. The sign-in, sign-up, password, e-mail verification, OAuth consent and device sign-in pages, and the four developer harness pages, load with their own routes; a visitor who opens `/login` sees the loading screen for a moment while that page's chunk arrives.
15+
- **`@object-ui/app-shell`.** The QR encoder used by the two-factor setup and the action result dialog loads when a QR code is first drawn. If it cannot load, the message shows in place of the code, as an encoding error already did.
16+
17+
Nothing to migrate.

‎ui/apps/console/src/App.tsx‎

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import { useNativeHostRouting } from '@object-ui/mobile';
1818
import { AuthProvider, useAuth, createAuthenticatedFetch } from '@object-ui/auth';
1919
import { UploadProvider } from '@object-ui/fields';
2020
import { createObjectStackUploadAdapter } from '@object-ui/data-objectstack';
21-
import { DevMasterDetail } from './dev/DevMasterDetail';
22-
import { DevLists } from './dev/DevLists';
23-
import { DevModal } from './dev/DevModal';
24-
import { DevLookup } from './dev/DevLookup';
2521
import {
2622
AiAddressRedirect,
2723
ConsoleShell,
@@ -59,15 +55,6 @@ import { useNativePushRegistration } from './nativePushRegistration';
5955
import { FormPage } from './components/FormPage';
6056
import { InternalFormRoute } from './components/InternalFormRoute';
6157
import { MetadataHmrReloader } from './components/MetadataHmrReloader';
62-
import { LoginPage } from './pages/auth/LoginPage';
63-
import { RegisterPage } from './pages/auth/RegisterPage';
64-
import { ForgotPasswordPage } from './pages/auth/ForgotPasswordPage';
65-
import { ResetPasswordPage } from './pages/auth/ResetPasswordPage';
66-
import { SetPasswordPage } from './pages/auth/SetPasswordPage';
67-
import { VerifyEmailPage } from './pages/auth/VerifyEmailPage';
68-
import { VerifyEmailPromptPage } from './pages/auth/VerifyEmailPromptPage';
69-
import { OAuthConsentPage } from './pages/auth/OAuthConsentPage';
70-
import { DeviceAuthPage } from './pages/auth/DeviceAuthPage';
7158

7259
/*
7360
* Package documentation portal (ADR-0046 section 6), lazy on purpose.
@@ -107,6 +94,33 @@ const SharedRecordPage = lazy(() => import('./pages/SharedRecordPage'));
10794
// every first load.
10895
const DevRowActions = lazy(() => import('./dev/DevRowActions'));
10996

97+
/*
98+
* The public auth pages and the dev harness pages are route-only: a signed-in
99+
* first screen draws none of them, so they load with their route instead of
100+
* riding every first load (objectstack#37572).
101+
*
102+
* The auth pages take NO `<Suspense>` of their own: they suspend into
103+
* `ConsoleShell`'s boundary, which also holds `NativeShellRouting`, so the
104+
* mobile shell's `ready()` still waits until the first route is on screen
105+
* (`/login` is the first route of a signed-out cold start). A boundary of
106+
* their own would commit the fallback and post `ready()` over it. The dev
107+
* pages sit behind `ProtectedRoute` and keep their own, as `DevRowActions`
108+
* above does.
109+
*/
110+
const LoginPage = lazy(() => import('./pages/auth/LoginPage').then((m) => ({ default: m.LoginPage })));
111+
const RegisterPage = lazy(() => import('./pages/auth/RegisterPage').then((m) => ({ default: m.RegisterPage })));
112+
const ForgotPasswordPage = lazy(() => import('./pages/auth/ForgotPasswordPage').then((m) => ({ default: m.ForgotPasswordPage })));
113+
const ResetPasswordPage = lazy(() => import('./pages/auth/ResetPasswordPage').then((m) => ({ default: m.ResetPasswordPage })));
114+
const SetPasswordPage = lazy(() => import('./pages/auth/SetPasswordPage').then((m) => ({ default: m.SetPasswordPage })));
115+
const VerifyEmailPage = lazy(() => import('./pages/auth/VerifyEmailPage').then((m) => ({ default: m.VerifyEmailPage })));
116+
const VerifyEmailPromptPage = lazy(() => import('./pages/auth/VerifyEmailPromptPage').then((m) => ({ default: m.VerifyEmailPromptPage })));
117+
const OAuthConsentPage = lazy(() => import('./pages/auth/OAuthConsentPage').then((m) => ({ default: m.OAuthConsentPage })));
118+
const DeviceAuthPage = lazy(() => import('./pages/auth/DeviceAuthPage').then((m) => ({ default: m.DeviceAuthPage })));
119+
const DevMasterDetail = lazy(() => import('./dev/DevMasterDetail').then((m) => ({ default: m.DevMasterDetail })));
120+
const DevLists = lazy(() => import('./dev/DevLists').then((m) => ({ default: m.DevLists })));
121+
const DevModal = lazy(() => import('./dev/DevModal').then((m) => ({ default: m.DevModal })));
122+
const DevLookup = lazy(() => import('./dev/DevLookup').then((m) => ({ default: m.DevLookup })));
123+
110124
const SERVER_URL = import.meta.env.VITE_SERVER_URL || '';
111125
const AUTH_URL = `${SERVER_URL}/api/v1/auth`;
112126

@@ -471,25 +485,25 @@ export function App() {
471485
{/* Dev-only: ADR-0001 master-detail subform verification harness. */}
472486
<Route path="/dev/master-detail" element={
473487
<ProtectedRoute>
474-
<DevMasterDetail />
488+
<Suspense fallback={<LoadingScreen />}><DevMasterDetail /></Suspense>
475489
</ProtectedRoute>
476490
} />
477491
{/* Dev-only: lightweight list primitives (definition-list, repeater). */}
478492
<Route path="/dev/lists" element={
479493
<ProtectedRoute>
480-
<DevLists />
494+
<Suspense fallback={<LoadingScreen />}><DevLists /></Suspense>
481495
</ProtectedRoute>
482496
} />
483497
{/* Dev-only: action modal transport (center/side/bottom/fullscreen). */}
484498
<Route path="/dev/modal" element={
485499
<ProtectedRoute>
486-
<DevModal />
500+
<Suspense fallback={<LoadingScreen />}><DevModal /></Suspense>
487501
</ProtectedRoute>
488502
} />
489503
{/* Dev-only: line-item grid with a lookup cell. */}
490504
<Route path="/dev/lookup" element={
491505
<ProtectedRoute>
492-
<DevLookup />
506+
<Suspense fallback={<LoadingScreen />}><DevLookup /></Suspense>
493507
</ProtectedRoute>
494508
} />
495509
{/* Dev-only: row-action inline-overflow (multiple primary actions). */}

‎ui/apps/console/src/__tests__/App.docsPortalLazy.test.tsx‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
* Two, because "the page never loaded" is exactly what a flag that can never
3333
* be set looks like.
3434
*
35-
* 1. `LoginPage` is a LIVE positive control: `App.tsx` still imports it
35+
* 1. `FormPage` is a LIVE positive control: `App.tsx` still imports it
3636
* statically, so its flag must already be set before the first render.
3737
* If the observer stopped seeing static imports, that assertion fails
3838
* instead of the lazy ones passing vacuously. (`SharedRecordPage` was the
39-
* control until objectui#13410 made `/s/:token` lazy too.)
39+
* control until objectui#13410 made `/s/:token` lazy too, and `LoginPage`
40+
* until objectstack#37572 made the auth pages lazy.)
4041
* 2. Visiting `/docs` must FLIP the layout's flag and render it. A flag that
4142
* is merely stuck at unset cannot satisfy both halves.
4243
*
@@ -131,14 +132,14 @@ vi.mock('../AppContent', () => ({
131132
vi.mock('../components/ProtectedRoute', () => ({ ProtectedRoute: passthrough }));
132133
vi.mock('../components/RootLandingRedirect', () => ({ RootLandingRedirect: stub('root-landing') }));
133134
vi.mock('../components/SetupRoute', () => ({ SetupRoute: stub('setup-route') }));
134-
vi.mock('../components/FormPage', () => ({ FormPage: stub('form-page') }));
135+
vi.mock('../components/FormPage', () => {
136+
loaded.FormPage = true;
137+
return { FormPage: stub('form-page') };
138+
});
135139
vi.mock('../components/InternalFormRoute', () => ({ InternalFormRoute: stub('internal-form-route') }));
136140
vi.mock('../components/MetadataHmrReloader', () => ({ MetadataHmrReloader: () => null }));
137141
// The statically imported positive control (counter-probe 1).
138-
vi.mock('../pages/auth/LoginPage', () => {
139-
loaded.LoginPage = true;
140-
return { LoginPage: stub('login-page') };
141-
});
142+
vi.mock('../pages/auth/LoginPage', () => ({ LoginPage: stub('login-page') }));
142143
vi.mock('../pages/auth/RegisterPage', () => ({ RegisterPage: stub('register-page') }));
143144
vi.mock('../pages/auth/ForgotPasswordPage', () => ({ ForgotPasswordPage: stub('forgot-page') }));
144145
vi.mock('../pages/auth/ResetPasswordPage', () => ({ ResetPasswordPage: stub('reset-page') }));
@@ -166,7 +167,7 @@ describe('the /docs portal is genuinely lazy (objectui#5467)', () => {
166167
// Counter-probe 1 — a page App.tsx still imports statically. Importing
167168
// `../App` above was enough to load it, which is what "eager" means and
168169
// what the four assertions below deny for the docs portal.
169-
expect(loaded.LoginPage).toBe(true);
170+
expect(loaded.FormPage).toBe(true);
170171

171172
expect(loaded.DocsLayout).toBeUndefined();
172173
expect(loaded.DocsIndex).toBeUndefined();

‎ui/apps/console/src/__tests__/App.nativeShellMode-29039.test.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525
import { describe, expect, it, vi, afterEach, beforeEach } from 'vitest';
26-
import { render, screen, cleanup, act } from '@testing-library/react';
26+
import { render, screen, cleanup, act, waitFor } from '@testing-library/react';
2727
import type { ReactNode } from 'react';
2828
import {
2929
NATIVE_CONNECTION_REMOVED_EVENT,
@@ -200,7 +200,11 @@ describe('the Console in the mobile shell', () => {
200200
const events = installBridge();
201201
render(<App />);
202202
expect(await screen.findByTestId('login-page')).toBeInTheDocument();
203-
expect(events).toEqual(['ready:login-page', 'route:/login']);
203+
// The auth pages are lazy, so the first route commits after a chunk
204+
// resolves and `ready()` / `routeChanged` run in that commit's passive
205+
// effects, which can land after the DOM query above returns. Wait for the
206+
// events; the `ready:` prefix still records what was on screen when it came.
207+
await waitFor(() => expect(events).toEqual(['ready:login-page', 'route:/login']));
204208
expect(document.documentElement.getAttribute('data-os-native-shell')).toBe('android');
205209
});
206210

@@ -216,7 +220,7 @@ describe('the Console in the mobile shell', () => {
216220
// The router pushed a history entry: an SPA move, not a document load.
217221
expect(window.location.pathname).toBe('/register');
218222
expect(window.history.length).toBe(before + 1);
219-
expect(events).toEqual(['ready:login-page', 'route:/login', 'route:/register?from=push']);
223+
await waitFor(() => expect(events).toEqual(['ready:login-page', 'route:/login', 'route:/register?from=push']));
220224
});
221225

222226
it('a route that is not an in-app path is left to the shell', async () => {
@@ -226,7 +230,7 @@ describe('the Console in the mobile shell', () => {
226230
const event = dispatchNavigate('//evil.example/register');
227231
expect(event.defaultPrevented).toBe(false);
228232
expect(window.location.pathname).toBe('/login');
229-
expect(events).toEqual(['ready:login-page', 'route:/login']);
233+
await waitFor(() => expect(events).toEqual(['ready:login-page', 'route:/login']));
230234
});
231235
});
232236

‎ui/apps/console/src/__tests__/App.nativeShellOpenSet-29330.test.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
*/
3131

3232
import { describe, expect, it, vi, afterEach, beforeEach, type Mock } from 'vitest';
33-
import { render, screen, cleanup } from '@testing-library/react';
33+
import { render, screen, cleanup, waitFor } from '@testing-library/react';
3434
import type { ReactNode } from 'react';
3535
import {
3636
NATIVE_HOST_GLOBAL,
@@ -186,8 +186,10 @@ describe('a shell whose platform is neither ios nor android', () => {
186186
const { rerender } = render(<App />);
187187
expect(await screen.findByTestId('login-page')).toBeInTheDocument();
188188

189+
// The auth pages are lazy: the first route's passive effects (`ready()`,
190+
// `routeChanged`, the root attribute) can run after the DOM query returns.
191+
await waitFor(() => expect(events).toEqual(['ready:login-page', 'route:/login']));
189192
expect(document.documentElement.getAttribute('data-os-native-shell')).toBe('desktop');
190-
expect(events).toEqual(['ready:login-page', 'route:/login']);
191193

192194
// Every typed call, from inside the running Console: the announced ones
193195
// reach the shell, the rest resolve `unavailable` without a call.
@@ -234,7 +236,7 @@ describe('a bridge speaking a newer protocol is no bridge', () => {
234236
const { events } = installBridge({ platform: 'ios', version: 1, capabilities: ['haptic'] });
235237
render(<App />);
236238
expect(await screen.findByTestId('login-page')).toBeInTheDocument();
239+
await waitFor(() => expect(events).toEqual(['ready:login-page', 'route:/login']));
237240
expect(document.documentElement.getAttribute('data-os-native-shell')).toBe('ios');
238-
expect(events).toEqual(['ready:login-page', 'route:/login']);
239241
});
240242
});

‎ui/apps/console/vite.config.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,14 @@ export default defineConfig({
15931593
// `plugin-chatbot` is reached only through the lazy chat surfaces.
15941594
// `includeDependenciesRecursively: false` for the reason `types-zod`
15951595
// above gives. ⛔ A module added to `core.ts` belongs in this list.
1596+
// `hitlContinuation` and `chat/questionSkip` were re-exported without
1597+
// being listed, and that put `plugin-chatbot` and `plugin-markdown`
1598+
// back into every first load (objectstack#37572). The eager-closure
1599+
// gate now fails when either chunk is eager
1600+
// (`evaluateLazyChatChunks` in `scripts/check-eager-closure-budget.mjs`).
15961601
{
15971602
name: 'plugin-chatbot-core',
1598-
test: /[\\/]packages[\\/]plugin-chatbot[\\/]src[\\/](core|useAgents|agentAliases|aiUsageEvents|publishHealth|toolResultParsers)\.tsx?$/,
1603+
test: /[\\/]packages[\\/]plugin-chatbot[\\/]src[\\/](core|useAgents|agentAliases|aiUsageEvents|publishHealth|toolResultParsers|hitlContinuation|chat[\\/]questionSkip)\.tsx?$/,
15991604
priority: 71,
16001605
includeDependenciesRecursively: false,
16011606
},

‎ui/packages/app-shell/src/console/RemediationOverlay.tsx‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { useEffect, useState } from 'react';
1010
import { useAuth } from '@object-ui/auth';
1111
import { Button, Input, Label } from '@object-ui/components';
1212
import { useObjectTranslation } from '@object-ui/i18n';
13-
import { toCanvas } from 'qrcode';
1413
import { useImpersonationExit, type ImpersonationExit } from '../layout/useImpersonationExit.js';
1514

1615
/**
@@ -239,7 +238,12 @@ function TotpQr({ uri }: { uri: string }) {
239238
const [error, setError] = useState<string | null>(null);
240239
const ref = (node: HTMLCanvasElement | null) => {
241240
if (!node || !uri) return;
242-
toCanvas(node, uri, { width: 184, margin: 1 }, (err) => { if (err) setError(err.message); });
241+
// `qrcode` loads when a QR first draws, not with every console page
242+
// (objectstack#37572). A failed chunk load shows its message in place of
243+
// the canvas, as an encoding error does.
244+
void import('qrcode')
245+
.then(({ toCanvas }) => toCanvas(node, uri, { width: 184, margin: 1 }, (err) => { if (err) setError(err.message); }))
246+
.catch((err: unknown) => setError(err instanceof Error ? err.message : String(err)));
243247
};
244248
return (
245249
<div className="flex justify-center rounded-md border bg-white p-3">

‎ui/packages/app-shell/src/views/ActionResultDialog.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import {
4343
import { useObjectTranslation } from '@object-ui/i18n';
4444
import { useActionDialogReturnFocus } from './actionDialogReturnFocus.js';
4545
import { Copy, Eye, EyeOff, Check } from 'lucide-react';
46-
import { toCanvas } from 'qrcode';
4746
// Aliased per PR #4169's convention — app-shell has its OWN `resolveI18nLabel`
4847
// for the KEYED vocabulary, which does not accept the inline per-locale map
4948
// this resolves. ⛔ Not `resolveKeyedI18nLabel`: the two are structurally
@@ -421,9 +420,15 @@ function QrcodeBlock({ value, copyName }: { value: string; copyName: string }) {
421420
const [error, setError] = useState<string | null>(null);
422421
const canvasRef = (node: HTMLCanvasElement | null) => {
423422
if (!node || !value) return;
424-
toCanvas(node, value, { width: 200, margin: 1 }, (err) => {
425-
if (err) setError(err.message);
426-
});
423+
// `qrcode` loads when a QR block first draws, not with every console page
424+
// (objectstack#37572). A failed chunk load falls back like an encoding error.
425+
void import('qrcode')
426+
.then(({ toCanvas }) =>
427+
toCanvas(node, value, { width: 200, margin: 1 }, (err) => {
428+
if (err) setError(err.message);
429+
}),
430+
)
431+
.catch((err: unknown) => setError(err instanceof Error ? err.message : String(err)));
427432
};
428433
return (
429434
<div className="space-y-2">

0 commit comments

Comments
 (0)