Repository navigation
Commit 47138b7
perf(console): keep the chat UI out of the first page load via @object-ui/plugin-chatbot/core (objectui#13410) (#13444)
<!-- claude-projects-attribution: {"github_login":"os-sales"} -->
_Requested by **Sales** · [project
thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuW9izc3zH47co5esYgQstYc)_
Fixes #13410
Clause-②: yes (widening)
Metadata-protocol: none
The Console's first page load no longer downloads the chat UI. The eager
closure drops by **254,055 gzipped bytes** (3,326,111 → 3,072,056), and
`plugin-chatbot-*` is no longer an eagerly loaded chunk.
## Why it was eager
Four static paths, each enough on its own to keep the whole
`plugin-chatbot` chunk group in every first load:
1. `app-shell` imported small helpers (`useAgents`, the agent alias
helpers, `AI_USAGE_REFRESH_EVENT`, `publishHealthFromResponse`,
`detectPendingApproval`) from the package root in 13 eager modules. The
root does `export * from './renderer'`, which registers the chat
components at module scope.
2. `ConsoleLayout` → `ChatDock` imported `ChatPane` (and with it
`AiChatPage`) statically.
3. `App.tsx` imported `DefaultAiChatPage` statically.
4. `App.tsx` imported `SharedRecordPage` (`/s/:token`, renders
`ChatbotEnhanced`) statically.
## What changed
- **`@object-ui/plugin-chatbot`**: new subpath export `./core`
(`src/core.ts`), side-effect-free: it re-exports only the hooks and
parsers above and their types. The two helpers that lived inside chat UI
modules move to `publishHealth.ts` and `aiUsageEvents.ts`;
`ChatbotEnhanced` and `useObjectChat` re-export them unchanged.
`dist/core.js` (5.3 KB, imports only `react`) comes from a second build
pass, `vite.core.config.ts`, because the main pass emits UMD and a
multi-entry lib build cannot. `dist/core.d.ts` comes from the main
pass's `dts` plugin. The existing `"."` export entry is untouched;
`"./core"` is added beside it.
- **`@object-ui/app-shell`**: every import of those names goes through
`@object-ui/plugin-chatbot/core`, including `AiChatPage`'s (it keeps the
root for the chat UI it renders). The ChatDock's default body moves to
`layout/ChatDockConversation.tsx` and loads through `lazy()`;
`resolveApiBase` moves to `console/ai/resolveApiBase.ts` and is
re-exported from `AiChatPage` unchanged.
- **`@object-ui/console`**:
- `/ai…` loads through the console-local module
`components/aiChatPage.ts`, on the `components/studioBuilder.ts`
pattern. `/s/:token` loads lazily too.
- `registerChatbotComponents.ts` registers `chatbot`, `chatbot-enhanced`
and `chatbot-floating` as lazy stubs. They used to be registered only as
a side effect of path 1. It is deliberately not in
`register-plugins.ts`, so the shipped `sdui.manifest.json` is unchanged.
Those three types were never in it, and adding them would change what
the host's save door accepts.
- `vite.config.ts` gets the `/core` alias and a `plugin-chatbot-core`
chunk group with `includeDependenciesRecursively: false`, so the core
modules are not co-tenants of the chat chunk.
- **Gate**: `MAX_EAGER_CLOSURE_GZIP_BYTES` 3,834,000 → 3,579,945, down
by exactly the measured drop, and `BASELINE` moves to the `b6f11d3`
reading. Left in place, the ceiling sat 744.1 KB over the new reading,
and the sensitivity half called it blind (exit 2) on the branch build.
Headroom stays 507,889 bytes (0.71x the regression), the same as `main`
had. Per-chunk rows are unchanged. Two test literals follow the new
rendering (`3049.3` → `3000.1`).
- **Tests**: mocks of the moved names now target
`@object-ui/plugin-chatbot/core` (33 files, mechanical: a root mock
whose only overrides were core names is retargeted, and a mixed one has
its `useAgents` override moved into a `/core` mock).
`ChatDock.partialRuntimeConfig` awaits the lazy body.
## Measurement
One container, one instrument: `CI=true pnpm exec vite build` in
`apps/console`, reading `dist/eager-closure.json`. Control `7981384`
(`main`, separate worktree) against `b6f11d3` (control + this PR's
source). Gzipped bytes:
| chunk | `7981384` | `b6f11d3` | delta |
|:--|--:|--:|--:|
| `plugin-chatbot` | 173,666 | — | −173,666 |
| `vendor-markdown` | 102,901 | 13,351 | −89,550 |
| `vendor-react-markdown` | 1,146 | 23,928 | +22,782 |
| `ui-components` | 296,133 | 308,400 | +12,267 |
| `plugin-chatbot-core` (new) | — | 5,735 | +5,735 |
| everything else | 1,006,784 | 975,161 | −31,623 |
| **aggregate** | **3,326,111** (78 of 2262) | **3,072,056** (85 of
2291) | **−254,055** |
`vendor-objectstack`, `framework` and `i18n-locale-en` are
byte-identical. "Everything else" is the `/ai` page and what only it and
the dock body reach (`AiChatPage`, `useChatConversation`,
`ConversationsSidebar`, `BuildDebugDrawer`, …) plus `SharedRecordPage`.
It was read module by module from `dist/stats.html` of a non-`CI` build
of each tree, which wrote the same totals to the byte.
**`vendor-markdown` (the card's optional question): mostly yes.** 89.5
KB of it leaves. About 35 KB of the markdown family stays eager, on
other lines: `MarkdownContent` in `packages/fields` (the objectui#5325
co-tenant of the eager `ui-components` chunk) reaches the `remark-gfm`
family. Those modules lost the `$initial` reach `vendor-markdown`'s tag
claims by, so `vendor-react-markdown` (+22,782) and `ui-components`
(+12,267, 60 modules) capture them. They were eager before and are eager
after, so they add no first-load bytes. `ui-components` stays under its
ceiling (301.2 / 338.9 KB).
## Accepted deviations
- **Done-when bullet 1 ("no non-test app-shell file imports the package
root")** is met for every helper import. Two files still import the root
for the chat UI itself, which `/core` must not carry: `AiChatPage.tsx`
(`ChatbotEnhanced`, `useObjectChat`, …) and, through it,
`ChatDockConversation.tsx`. Both are reached only through `lazy()`,
which is the "behind the chat surface's own dynamic import" route of
bullet 2. The build confirms it: no eager chunk holds a
`packages/plugin-chatbot` module outside `plugin-chatbot-core`.
- **No `sideEffects` field** on `plugin-chatbot`'s `package.json`. The
fix does not depend on it, and a list that missed one side-effectful
module would silently drop it from a consumer's bundle.
- **No new guard.** The reverted tree (`7981384`) still passes under the
lowered aggregate line, because 254,055 is inside the 695 KiB band the
objectui#12653 ruling accepted. A regression would show as
`plugin-chatbot` in `Bundle Analysis`'s largest-chunks list. Per the
startup-stage rule, a new gate needs a maintainer's call, so I did not
add one. The budget docblock says so.
## Verification (on `b6f11d3` / branch tip)
| command | verdict |
|:--|:--|
| `pnpm exec vitest run packages/plugin-chatbot/
packages/app-shell/src/{layout,hooks,console/ai,console/home,views/studio-design,preview,views/metadata-admin/previews}
apps/console/src/pages/system` | `Test Files 777 passed`, after the one
remaining file (`ChatDock.partialRuntimeConfig`) was fixed and re-run:
4/4 |
| `pnpm exec vitest run
scripts/__tests__/check-eager-closure-budget.test.ts
scripts/__tests__/ci-cd-pipeline-doc.test.ts
scripts/__tests__/render-budget-comment.test.ts` | 305/305 |
| `NODE_OPTIONS=--max-old-space-size=8192 pnpm turbo run type-check
--filter=@object-ui/app-shell --filter=@object-ui/plugin-chatbot
--filter=@object-ui/console` | 38/38 tasks, includes the new
`plugin-chatbot` build (`dist/core.js`, `dist/core.d.ts`) |
| `pnpm check:eager-closure` on the branch build | exit 0, aggregate
3000.1 / 3496.0 KB (0.71x), membership exact |
| `pnpm
check:{phantom-deps,unused-deps,self-import,dist-completeness,esm-specifiers,node-esm-load,published-dist,published-tsconfig-exclude,registry-bare-names,side-effects-array,sdui-registration-pins,docs-route-closure,entry-guard,test-path-roots,vi-mock-specifiers,vi-mock-inherit,vi-mock-override-shape,readme-exports,unreferenced-sources,changeset-claims,pending-changeset-literals,installed-pin-claims,new-line-citations,control-bytes}`
| all exit 0 |
| `pnpm exec eslint` on the changed `.ts`/`.tsx` files | 0 errors (90
existing warnings, none new in kind) |
NOT RUN locally: the full repo test suite, Playwright E2E, and a live
browser run of the dock and `/ai` against a server. CI covers the first
two.
## Acceptance notes
- The objectui#5325 co-tenancy (`MarkdownContent` in eager
`ui-components`, reached only through `React.lazy`) now holds the ~35 KB
of markdown modules that are still eager. It is already on the ledger in
`scripts/vite-ineffective-dynamic-imports.ts`. Not filed again.
- [x] Adds no product-specific widget, dialog, hook or string (see
AGENTS.md › Product-neutral renderer)
Session: `https://claude.ai/code/session_0191T4aUg1GgkiMr5zR3m5sx`
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_0191T4aUg1GgkiMr5zR3m5sx
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 576fd25 commit 47138b7
66 files changed
Lines changed: 841 additions & 420 deletions
File tree
- .changeset
- apps/console
- src
- __tests__
- components
- packages
- app-shell/src
- console
- ai
- __tests__
- home
- __tests__
- hooks
- __tests__
- layout
- __tests__
- preview
- views
- metadata-admin/previews
- studio-design
- __tests__
- plugin-chatbot
- src
- scripts
- __tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
50 | 49 | | |
51 | 50 | | |
52 | 51 | | |
53 | | - | |
54 | 52 | | |
55 | 53 | | |
56 | 54 | | |
| |||
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
250 | 265 | | |
251 | 266 | | |
252 | 267 | | |
253 | | - | |
| 268 | + | |
254 | 269 | | |
255 | 270 | | |
256 | 271 | | |
| |||
388 | 403 | | |
389 | 404 | | |
390 | 405 | | |
391 | | - | |
| 406 | + | |
392 | 407 | | |
393 | 408 | | |
394 | 409 | | |
395 | 410 | | |
396 | | - | |
| 411 | + | |
397 | 412 | | |
398 | 413 | | |
399 | 414 | | |
400 | 415 | | |
401 | | - | |
| 416 | + | |
402 | 417 | | |
403 | 418 | | |
404 | 419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
| 35 | + | |
| 36 | + | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
156 | 160 | | |
157 | 161 | | |
158 | 162 | | |
159 | | - | |
| 163 | + | |
160 | 164 | | |
161 | 165 | | |
162 | 166 | | |
| |||
| 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 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| |||
| 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 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
656 | 659 | | |
657 | 660 | | |
658 | 661 | | |
| |||
1475 | 1478 | | |
1476 | 1479 | | |
1477 | 1480 | | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
1478 | 1499 | | |
1479 | 1500 | | |
1480 | 1501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | 62 | | |
64 | 63 | | |
65 | 64 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | 65 | | |
76 | 66 | | |
77 | 67 | | |
| |||
80 | 70 | | |
81 | 71 | | |
82 | 72 | | |
83 | | - | |
84 | 73 | | |
85 | 74 | | |
86 | 75 | | |
87 | 76 | | |
88 | 77 | | |
89 | | - | |
90 | 78 | | |
91 | 79 | | |
92 | 80 | | |
| |||
103 | 91 | | |
104 | 92 | | |
105 | 93 | | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
106 | 110 | | |
107 | 111 | | |
108 | 112 | | |
| |||
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
141 | | - | |
142 | | - | |
| 145 | + | |
143 | 146 | | |
144 | 147 | | |
145 | 148 | | |
| |||
464 | 467 | | |
465 | 468 | | |
466 | 469 | | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
471 | | - | |
472 | | - | |
473 | | - | |
474 | | - | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
475 | 473 | | |
476 | 474 | | |
477 | 475 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
0 commit comments