Skip to content

refactor: write component assets as single literals - #457

Merged
JuroOravec merged 1 commit into
mainfrom
refactor/single-literal-assets
Oct 28, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
refactor/single-literal-assets

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

What changed

citry format cannot read a component template or js that is built
by joining string pieces or by adding a shared fragment, and the
authoring rule in CLAUDE.md asks for one triple-quoted literal assigned
directly. This writes those assets out as single literals. Every string
value stays the same.

Converted:

  • Implicit concatenation: cform_collection, ctransfer_list,
    benchmarks/web/apps/citry/app.py (two assets).
  • ANCHORED_LAYER_RUNTIME_JS + r"""...""" (an 8-line fragment, written
    out): cdisclosure, chover_card, cmulti_select, cpopover,
    ctooltip, and CMenuSubmenu in cmenu.
  • Also found by scanning the same files for the same pattern, and fixed:
    cform and ctoggle (implicit concatenation in js).
  • packages/py/citry/tests/test_secret.py: five class bodies used
    js = _COMPONENT_JS; they now hold the 3-line literal. The constant
    stays for the two dict-style class definitions.

Where a line is longer than 119 characters inside a string (cform,
cform_collection, ctoggle, ctransfer_list), the closing quotes
carry # noqa: E501 so the value is not reflowed. The formatter will
reflow them later.

Left as they are (computed by design)

  • cmenu: CMenu.js is generated by build_shared_component_assets
    (runtime key, generation and a source fingerprint are filled in), and
    _MENU_ITEM_JS is a 275-line script shared by three item components.
  • cslider: _SLIDER_TEMPLATE (140 lines) and _SLIDER_JS (510 lines)
    are shared by CSlider and CRangeSlider.
  • calert_dialog: js = CDialog.js reuses the 350-line Dialog script;
    its Dependencies come from CDialog.Dependencies.
  • docs_site/_internal/components/landing_composer.py:
    LandingRecipeBank.template is generated from the _RECIPES data in
    a loop.
  • ctable.py is untouched (formatter bug, handled separately).

Not touched, same pattern outside the listed files:
benchmarks/client_scenario.py, benchmarks/i18n.py (shared constants).

Evidence

  • A script that imports each changed citry_ui module before and after
    and compares every template/js/css class attribute: all equal.
    The benchmark app was compared with ast the same way.
  • test_secret.py literals sit at the indentation of their class body,
    so they differ from _COMPONENT_JS only by indentation, which Citry
    removes when it loads the asset. 69 tests pass.
  • Component tests for the 10 changed citry_ui components plus
    packages/py/citry_ui/tests (no e2e): 941 passed. The type-check and
    JavaScript-name tests: 2 passed, 1 skipped. calert_dialog and
    cslider: 52 passed.
  • citry format --check --embedded off no longer reports an error for
    any changed file except ctransfer_list: it now reports a different
    problem, a formatter invariant failure on its multi-line attribute
    expressions (for example c-aria-label=" followed by an expression on
    the next lines). A three-line example reproduces it. That is a
    separate formatter bug, not part of this change. The others report
    "would format" or unchanged.
  • ruff check and ruff format --check pass on all changed files.
  • An independent review agent re-checked every value and found no
    differences.

No changelog entry: internal refactor.

🤖 Generated with Claude Code

citry format cannot read a template or js value that is built by
implicit string concatenation or by adding a shared fragment, and the
authoring rule asks for one triple-quoted literal. Write out the
affected assets with identical string values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 8bfb23e into main Oct 28, 2026
28 of 37 checks passed
@JuroOravec
JuroOravec deleted the refactor/single-literal-assets branch October 28, 2026 10:14
JuroOravec added a commit that referenced this pull request Oct 28, 2026
…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]>
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