Skip to content

fix(ui): type the shadow-root walk and the disclosure state for TypeScript - #534

Merged
JuroOravec merged 1 commit into
mainfrom
fix/citry-ui-ts-findings
Oct 28, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/citry-ui-ts-findings

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Main's Ubuntu Python test jobs fail packages/py/citry_ui/tests/test_citry_ui_type_check.py::test_citry_ui_components_have_no_typescript_or_ty_findings with six TypeScript ts2339 findings. This PR fixes the types rather than suppressing them.

Why it started failing

The editor's TypeScript check reads a component's inline js only when it is a single string literal. #457 (8bfb23e) turned the ANCHORED_LAYER_RUNTIME_JS + r"""...""" concatenations into single literals, so these scripts were checked for the first time. In the CI run at 33c9531, the commit before #457, this test reported no findings. The run at 8bfb23e (#457) is the first to report these six. The code that causes them was already there; #457 only made TypeScript read it.

What changes

  • host on Node (chover_card, cmulti_select, cpopover, ctooltip). These components walk outward from an inline trigger to the nearest ancestor that is not inline, because a ResizeObserver reports nothing for an inline element. On the way they step out of a shadow root to its host. TypeScript types box.getRootNode() as returning a Node, which has no host. The walk now checks instanceof ShadowRoot first, as _anchored_layer.py and cmenu.py:1671 already do. It types box as Element, because TypeScript types a shadow root's host as Element. A document root still ends the walk, so the behavior is the same for nodes in the page's own document.
  • __citryUiDisclosureRuntime on HTMLDivElement (cdisclosure). The disclosure keeps its browser-side state on its root element. The root is now cast to an element type that declares that property, as caccordion, clistbox, ctag and ctree already do.
  • cmenu has the same walk in _runtime_source, which is built by concatenation, so TypeScript does not check it. It gets the same change so the inline copies match.

Five runtime.source.js files still read getRootNode().host: cselect:121 (the same walk), ctour:334, ccascader:170, ccolor_picker:40 and ccontext_menu:536/565/1453. TypeScript does not check them, because each one is the source of a minified runtime.min.js, so this PR leaves them alone. Changing them means rebuilding the minified files, which suits a separate sweep.

Evidence

  • On unchanged main, the type-check test reports CI's six findings locally. With this change it reports none of them. Local runs also show seven caccordion findings (string | boolean | string[], lines 934 to 963), with or without this change. CI does not report those, so they most likely come from my local environment, which uses an older Rust core.
  • test_asset_budgets.py passes, and pnpm run citry-ui:check-assets passes. ruff and ruff format pass.
  • I could not run the browser tests for these components locally. My local Rust core is 0.420.0+citry.6, and main needs citry.7 (fix: read v-pre content as plain, as Vue 3.5 does #525), so rendering stops with "unknown compiler identity". This PR's CI runs them.

🤖 Generated with Claude Code

…cript

Since #457 wrote these components' `js` as single string literals, the
editor's TypeScript check reads them, and main's Ubuntu Python test jobs
fail `test_citry_ui_components_have_no_typescript_or_ty_findings` with
six ts2339 findings:

- chover_card, cmulti_select, cpopover and ctooltip walk outward from an
  inline trigger to the nearest ancestor with a box of its own, stepping
  out of a shadow root with `box.getRootNode().host`. TypeScript types
  `getRootNode()` as returning a `Node`, which has no `host`. The walk now
  checks `instanceof ShadowRoot` first, the way `_anchored_layer.py`
  does, and types `box` as `Element`, because TypeScript types a shadow
  root's host as `Element`. A document root still ends the walk, as
  before.
- cdisclosure keeps its browser-side state in
  `root.__citryUiDisclosureRuntime`. The root is now cast to an element
  type that declares that property, the way caccordion, clistbox, ctag
  and ctree already do.

cmenu has the same walk in `_runtime_source`, which is built by
concatenation, so TypeScript does not check it. It gets the same change
so the inline copies match. cselect's copy in `runtime.source.js` keeps
the old form, because changing it means rebuilding its minified file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec force-pushed the fix/citry-ui-ts-findings branch from 1c5f394 to 52b5a18 Compare October 28, 2026 22:28
@JuroOravec
JuroOravec merged commit 342bc94 into main Oct 28, 2026
0 of 6 checks passed
@JuroOravec
JuroOravec deleted the fix/citry-ui-ts-findings branch October 28, 2026 22:29
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.

1 participant