Skip to content

Commit d746da6

Browse files
authored
fix(css): make heading scale resilient — target markdown-block, not hook class (#503)
The heading size overrides used .pi-assistant-body h1 which depends on applyMessageStyleHooks() stamping the class on the right DOM node. When the hook didn't run (streaming, DOM structure changes from dep bumps, timing races), headings fell back to Tailwind v4's base reset (font-size: inherit) or browser defaults (2em) — both much too large for the sidebar. Now target 'markdown-block h1' directly. markdown-block is a stable custom element tag in pi-web-ui's light DOM that always exists in the render tree, so headings are always capped regardless of hook state. This is the root cause behind the recurring 'headings too large' reports — the same fragility pattern (hook-dependent selectors failing when upstream components change) also caused the KaTeX and thinking block issues fixed earlier.
1 parent fb119d8 commit d746da6

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

src/ui/theme/content/message-components.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ thinking-block markdown-block {
131131
overscroll-behavior: contain;
132132
}
133133

134+
/* Compact heading scale for thinking blocks — override the global
135+
markdown-block heading rules which are sized for the message body. */
136+
thinking-block markdown-block h1,
137+
thinking-block markdown-block h2,
138+
thinking-block markdown-block h3 {
139+
font-size: var(--text-sm);
140+
font-weight: 700;
141+
margin: 8px 0 4px;
142+
}
143+
thinking-block markdown-block h4,
144+
thinking-block markdown-block h5,
145+
thinking-block markdown-block h6 {
146+
font-size: var(--text-sm);
147+
font-weight: 600;
148+
margin: 6px 0 3px;
149+
}
150+
134151
/* Added by applyMessageStyleHooks() so we don't depend on utility classes. */
135152
.pi-thinking-label--streaming {
136153
animation-duration: 1.2s;

src/ui/theme/content/messages.css

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,43 +33,60 @@ assistant-message { margin-right: var(--pill-inset); }
3333
}
3434

3535
/* ── Markdown heading scale (sidebar-appropriate) ───────────── */
36+
/*
37+
* IMPORTANT: target `markdown-block h1` (stable custom-element tag), NOT
38+
* `.pi-assistant-body h1` (hook-dependent class).
39+
*
40+
* Tailwind v4's base reset (`@layer base`) sets
41+
* h1,h2,...,h6 { font-size: inherit; font-weight: inherit }
42+
* which strips browser defaults. Our overrides are unlayered so they win
43+
* over the reset, but ONLY if the selector actually matches. The old
44+
* `.pi-assistant-body h1` selector failed whenever the style hook didn't
45+
* run (streaming, DOM structure changes from upstream bumps, timing
46+
* races) — leaving headings at `inherit` with no cap.
47+
*
48+
* Using `markdown-block h1` always matches because `markdown-block` is a
49+
* stable custom element tag in pi-web-ui's light DOM. This also covers
50+
* headings inside thinking blocks and tool cards without needing separate
51+
* overrides (those have their own more-specific rules if needed).
52+
*/
3653

37-
.pi-assistant-body h1 {
54+
markdown-block h1 {
3855
font-size: var(--text-lg);
3956
font-weight: 700;
4057
line-height: 1.3;
4158
margin: 16px 0 8px;
4259
}
4360

44-
.pi-assistant-body h2 {
61+
markdown-block h2 {
4562
font-size: var(--text-md);
4663
font-weight: 700;
4764
line-height: 1.35;
4865
margin: 14px 0 6px;
4966
}
5067

51-
.pi-assistant-body h3 {
68+
markdown-block h3 {
5269
font-size: var(--text-base);
5370
font-weight: 700;
5471
line-height: 1.4;
5572
margin: 12px 0 4px;
5673
}
5774

58-
.pi-assistant-body h4,
59-
.pi-assistant-body h5,
60-
.pi-assistant-body h6 {
75+
markdown-block h4,
76+
markdown-block h5,
77+
markdown-block h6 {
6178
font-size: var(--text-base);
6279
font-weight: 600;
6380
line-height: 1.4;
6481
margin: 10px 0 4px;
6582
}
6683

67-
.pi-assistant-body h1:first-child,
68-
.pi-assistant-body h2:first-child,
69-
.pi-assistant-body h3:first-child,
70-
.pi-assistant-body h4:first-child,
71-
.pi-assistant-body h5:first-child,
72-
.pi-assistant-body h6:first-child {
84+
markdown-block h1:first-child,
85+
markdown-block h2:first-child,
86+
markdown-block h3:first-child,
87+
markdown-block h4:first-child,
88+
markdown-block h5:first-child,
89+
markdown-block h6:first-child {
7390
margin-top: 0;
7491
}
7592

0 commit comments

Comments
 (0)