Commit e33df11
fix(chat): lifecycle-guaranteed root token injection (production regression) (#375)
`ensureChatRootStyles()` injects the chat lib's root CSS custom
properties — `--ngaf-chat-bg`, `--ngaf-chat-surface`,
`--ngaf-chat-radius-input`, `--ngaf-chat-sidenav-width-expanded`,
`--ngaf-chat-font-family`, the edge-claim primitive, the
data-ngaf-chat-theme attribute mappings, and reduced-motion overrides.
Every host-encapsulated chat lib style references these via `var()`.
It was wired as a module-evaluation side effect (auto-call at the bottom
of chat-tokens.ts). The published artifact's `sideEffects` glob was
`["**/chat-tokens.ts", "**/*.css"]` — the chat-tokens.ts glob matches
the *source* tree (workspace TS paths in this repo) but matches nothing
in the bundled `dist/libs/chat/fesm2022/ngaf-chat.mjs` artifact. When
a consumer's bundler does aggressive production tree-shaking it sees
no side-effect-marked files in the published package and treats the
entire bundle as side-effect-free. Result: the module-eval call is
dropped, the style element is never injected, and every chat surface
renders without chrome — sidenav has no width, input has no border,
chips have no pill background, suggestions look like plain text on
the page bg.
This shipped in production at https://demo.cacheplane.ai but doesn't
reproduce locally (dev mode skips tree-shaking; workspace TS paths
match the source glob). Verified live: manual injection of the root
tokens via browser console restored every chrome element instantly.
Fix:
- Call `ensureChatRootStyles()` from the constructors of every
top-level chat composition (`ChatComponent`, `ChatPopupComponent`,
`ChatSidebarComponent`, `ChatDebugComponent`). The function is
idempotent (early-returns if the style element already exists).
Constructors are reachable from user code, so bundlers can't
tree-shake the call.
- Extend `libs/chat/package.json` `sideEffects` to also match
`./fesm2022/ngaf-chat.mjs` — defense-in-depth for any consumer
bundler that DOES respect the field.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 8e4d5fe commit e33df11
5 files changed
Lines changed: 28 additions & 3 deletions
File tree
- libs/chat
- src/lib/compositions
- chat-debug
- chat-popup
- chat-sidebar
- chat
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
399 | 400 | | |
400 | 401 | | |
401 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
402 | 407 | | |
403 | 408 | | |
404 | 409 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
398 | 411 | | |
399 | 412 | | |
400 | 413 | | |
| |||
0 commit comments