Skip to content

fix: keep host page styles off code, lists and text in widget replies - #601

Merged
neuromechanist merged 5 commits into
OpenScience-Collective:developfrom
bendichter:fix/widget-host-css-leak
Oct 8, 2026
Merged

neuromechanist merged 5 commits into
OpenScience-Collective:developfrom
bendichter:fix/widget-host-css-leak

Conversation

@bendichter

@bendichter bendichter commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Part of #597 (the reply content; what is left of the widget is under Not covered).

Summary

On a Sphinx docs site the host theme's rules on bare elements reach the widget's replies wherever the widget's stylesheet leaves a property unset. With sphinx_rtd_theme a code block collapses onto one line (white-space: nowrap on code), inline code turns red with a border, list markers disappear and paragraph text grows to 16px. With the PyData theme inline code turns purple.

This sets those properties explicitly in the .osa-message-content rules: color, border, white-space, max-width, overflow and line-height on code; white-space: pre on pre code; font-family, font-size, line-height, border and clear on pre; font-size and line-height on p; font-family and color on headings; list-style-type on lists. Stylesheet only.

On a page with no host styles nothing changes: each value is what the element already computed to there.

Tests

  • Headless Chromium, the same reply HTML (paragraph with inline code, link, bold, headings, a code block, lists, a table) in an assistant bubble on a bare page and on the Read the Docs previews of the six NWB docs sites, every computed style compared element by element. Before: 11 kinds of reply element differ on the five sphinx_rtd_theme sites and 4 on the PyData one. After: none on any of the six.
  • bun frontend/test-markdown.js (31 passed), test-widget-color-scheme.js (128), test-widget-first-paint.js (91), test-widget-capsule.js (133), test-citation-markers.js (10), test-streaming.js (all passed), with bun 1.4.2.
  • node --check frontend/osa-chat-widget.js.
  • New automated test, frontend/test-widget-host-styles.js, below. The comparison against the real theme stylesheets needs a real browser and is not part of the suite.

Not covered

The rest of the widget is still reachable by host rules (box-sizing: border-box on every element, fonts on the header buttons and the input); see #597.

Review follow-up

Commits added to this branch after review (a99a279 to 58d1d82):

  • Inline code and pre take line-height and font-size from the reply (inherit) instead of a fixed 1.5 and 14px, so a heading containing code keeps the heading's line height and a different bubble font size carries through. List markers use revert, not disc and decimal, so nested lists keep their circles and squares.
  • The "Run this Python?" and run-code cards render code outside the reply and took the host's code and pre rules too. The card's pre gets an explicit border and line height; its code is all: revert, which is exactly what a page with no host styles gives it.
  • The same treatment for the other reply properties a theme sets: li, th and td font size and line height, list marker position and image, table cell vertical alignment, caption side and row border style, hr height, opacity and color, strong and em color, link hover color and underline offset, the citation superscript's position, and the fonts of the copy and run buttons.
  • New test frontend/test-widget-host-styles.js (39 checks, registered in test.yml and tests.yml): the widget in happy-dom under a page with Read the Docs and PyData rules on code, pre, p, li and h2, computed styles for what happy-dom resolves (a plain <code> outside the widget is the control that the host rule is live), and stylesheet pins for inherit, revert and all. Against develop's stylesheet 32 of its 39 checks fail.

Additional tests:

  • Headless Chrome 154, the same reply and card markup (headings with inline code, nested lists, a code block with its copy button, a table, hr, citations, sources, usage line, both code cards) on a bare page and under the real sphinx_rtd_theme (PyNWB) and PyData (NeuroConv) stylesheets, every computed property of every element compared. Bare page, light and dark: zero differences from develop. Under both themes, none from code, pre, lists, headings, tables, hr, links, the citation or the buttons; what is left is the text color the code cards inherit from the page body.
  • All widget tests CI runs pass with bun 1.4.2, and node --check on the widget.

Not covered:

  • The cards' chrome (panel title, toolbar) inherits the page's text color, which a docs theme sets on body. Fixing it would change the card on a bare page (black to the widget's text color), so I left it.
  • box-sizing: border-box on every element, -webkit-tap-highlight-color and text-size-adjust from a host's * rules, and the header buttons and input, as in the first version.
  • A host rule with higher specificity than the widget's (#content code) still wins; no stylesheet rule can stop that short of !important.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Review of the host-style protection: inline code and pre take line-height and
font-size from the reply instead of a fixed 1.5 and 14px, and list markers revert
to the browser default so nested lists keep their circles. Tested in headless
Chrome: zero computed-style differences from develop on a bare page, light and dark.
The Run this Python and run-code cards render code outside the reply, so they took
a host theme's code rules (border, padding, font, nowrap). The card's pre gets an
explicit border and line height, its code reverts to browser defaults. Tested in
headless Chrome: zero differences on a bare page, none from the code rules under
the Read the Docs and PyData themes.
…t host styles

Same approach for the other reply properties a docs theme sets: li/th/td font size
and line height, list marker position and image, table vertical alignment and
border style, hr height, opacity and color, strong and em color, link hover color
and underline offset, citation superscript position, copy and run button fonts.
Tested in headless Chrome: zero differences from develop on a bare page, light
and dark; the only differences left under the two themes are text color inherited
by the cards from the page body.
Runs the widget in happy-dom under a page that carries Read the Docs and PyData
style rules on code, pre, p, li and h2: computed styles for what happy-dom
resolves, a plain code element outside the widget as the control, and stylesheet
pins for inherit and revert. 39 checks pass; against develop's stylesheet 31 fail.
Registered in test.yml and tests.yml.
@neuromechanist
neuromechanist merged commit 7f08ee5 into OpenScience-Collective:develop Oct 8, 2026
7 of 8 checks passed
neuromechanist pushed a commit that referenced this pull request Oct 10, 2026
Retitles [Unreleased] to [0.8.18], as for earlier releases. Adds the entries
that were missing for #599 (hed-suggest in the image), #600 (HED prompt),
#601 (widget host styles) and #605 (live tests by hand), and one for the
DEFAULT_MODEL check at startup. Names the three classes that are accepted
(the other five are refused), and fixes a reference that pointed the wrong way.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019MtQNfPzMpGxEJFUciXbTN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants