Skip to content

feat(serialize): name each separate asset tag's components, and OutsideSlotContentError - #805

Merged
JuroOravec merged 1 commit into
mainfrom
feat/asset-owner-and-island-error
Nov 19, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
feat/asset-owner-and-island-error

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

(Opus 5.5)

Two small Experimental additions for citry 1.1.0, groundwork for the citry-django integration. citry-django renders each interactive region of a Django page as its own Vue app with serialize_result(deps_position="separate"). Its compressor today reads Citry's internal data-citry-css-class attribute from tag text, and it recognises the island slot-content refusal by its message text. This PR gives it a public API for each. It builds on #801 and #802 (combine_assets), both merged, and does not conflict with #803.

1. SerializedAssetEntry: which components declared a tag

Prior art. Dependency.origin_class_id and kind (ext/dependencies/types.py) already record the declaring class and whether a sheet holds css_data() values ("variables"). _resolve_records (ext/dependencies/emission.py) already tracks which instances list each dependency. SerializedScriptSecurity.origin_class_id exposes the owner for scripts in security metadata. data-citry-css-class lists the owners of a component's own sheet in static output only, and it is tag text. The compressor (citry_django_compressor/__init__.py, PageTag.origin_class_id and shareable) needs two answers per tag: which class declared it (to look up css_file and choose a precompiler), and whether an inline <style> is the same on every page or holds one instance's data.

API.

  • SerializedAssets gains css_entries and js_entries. They hold the same tags as css/js, in the same order, each as a SerializedAssetEntry(tag, class_ids, instance).
  • class_ids lists every component that declared the tag. It is a tuple because byte-identical CSS or a shared file can have several owners.
  • instance=False only when Citry's records prove the tag is the same on every render: runtime_assets tags, a component's own tags, and Dependencies tags. A css_data() sheet, every app_assets tag, and any tag no record names (a tag an on_dependencies hook added or rebuilt) report True, so the flag fails closed. Setting origin_class_id on a hook's tag names its component, but it does not make the tag shareable.
  • The existing css/js fields and their behavior are unchanged. Creating a SerializedAssets whose entries name other tags raises ValueError.
  • combine_assets() combines the entries too: a merged tag lists the components of every tag it replaced and is instance when any of them was. When a group has tags but no entries (a hand-built group), the result has none for that kind. feat(vue): one stylesheet tag for several apps, and experimental combine_assets() #802 was already merged, so this PR updates combine_assets directly.

How owners travel. Each wrapper comment that "separate" puts around a tag now carries only the tag's position in a per-call list. The emitter fills that list from the dependency records, and the serializer reads it when it cuts the tags out. No owner is ever read from tag text, and page data cannot write a wrapper because it cannot know the per-call 128-bit value.

Alternatives rejected.

  • Parse data-citry-css-class from the tag, or encode the class ids into the wrapper comment and read them back. Both read owners out of HTML text, and the attribute exists only on static component sheets.
  • Parallel css_owners tuples aligned by index with css. Every consumer would have to zip the two and keep them in step. An entry that holds its own tag is self-contained and survives combine_assets.

What would show it is wrong. An entry whose class_ids comes from a tag's attributes, or a one-render tag (css_data() or hook-built) reported instance=False. test_owners_come_from_records_not_from_the_tag_text and test_a_stylesheet_a_hook_rebuilds_is_never_shareable cover both.

2. OutsideSlotContentError

Prior art. #801 raises an internal UnsupportedPreparedView (a TypeError) from _stable_owner in _vue/direct_capture.py when a child holding slot content from outside it is serialized as its own Vue app. None of the four except UnsupportedPreparedView sites wraps _stable_owner.

API. citry.OutsideSlotContentError(TypeError), Experimental, raised at that one site. except TypeError still catches it. The docs for needs_browser_runtime(), serialize() (Raises) and "Split into several apps" name it.

Alternatives rejected.

  • Make the public class a subclass of the internal UnsupportedPreparedView. That exposes an internal class in a public class's base classes.
  • An error code attribute on the plain TypeError. Callers would still need to inspect the error instead of catching it by type.

What would show it is wrong. Code that caught the old exception no longer catching it. It is still a TypeError, and no internal handler covered that raise.

Checks

  • Tests: 9 new tests (13 cases) in test_serialize_separate_assets.py, and 2 updated. The four focused files (separate assets, Vue migration coverage, deps emission, serialize security) pass: 728 tests. The full citry suite (no e2e) passed 14,789 tests before the review fixes. Its 3 failures and 11 collection errors come from the minimal venv: missing yaml/citry_ui, two tests that also fail on base, and a timing test that passes alone.
  • ruff clean on the changed code. mypy on packages/py/citry/citry: no issues on macOS or with --platform linux.
  • Benchmarks, base origin/main against this branch, fresh processes alternating, best of 15 renders (budget about 5 minutes, threshold 3%):
    • benchmarks/slot_renders.py --scenario filled --runs 5: base median 20.23 ms, head 20.48 ms (+1.2%, within noise; this path does not reach the changed code).
    • Document serialize, 200 interactive components: median 13.93 ms against 13.92 ms (-0.03%).
    • Document serialize, 300 components with css_data(): median 51.01 ms against 51.43 ms (+0.8%).
    • The second and third used an inline harness, because benchmarks/client_scenario.py on main uses template syntax that has since been removed.
  • Independent reviewers: a security and technical review (Mechanism 7 brief naming "Markers for Citry's browser code"; Mechanism 8 advisory survey read, kinds checked: cross-user cache, trusted shape, hydration markers, mXSS, ReDoS), and a separate cold read and prose pass.

Fixed during the review

  • instance used to report a tag as shareable whenever Citry could not tell, for example a css_data() sheet that a hook rebuilt. It now fails closed. The reviewer re-ran its test scripts and confirmed the fix.
  • The docs section's placement, its heading, and the claim that every app_assets tag has empty class_ids were corrected.

Versioning

Additions only, all Experimental and named in the Experimental list on the versioning page. The new exception subclasses TypeError, so existing handlers keep working. A minor release (1.1.0) fits. The wrapper comment is internal to one serialize call and never leaves it. Changelog: one entry under Unreleased > Added for each change, marked as groundwork for the citry-django integration.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom

…deSlotContentError

Each SerializedAssets group that deps_position="separate" returns now has
css_entries and js_entries: the same tags as css and js, each as a
SerializedAssetEntry with the class ids of the components that declared it
and an instance flag that is True when the tag may hold one render's data.
Citry fills them from its dependency records: each wrapper comment carries
only the tag's position in a per-call list, so no owner is read from tag
text. A tag no record names, such as one an on_dependencies hook added or
rebuilt, reports instance=True. combine_assets() combines the entries.

Serializing a child render on its own when it holds slot content from
outside now raises OutsideSlotContentError, a TypeError subclass.

Both are Experimental, groundwork for the citry-django integration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
@JuroOravec
JuroOravec merged commit ccc0bf7 into main Nov 19, 2026
16 of 34 checks passed
@JuroOravec
JuroOravec deleted the feat/asset-owner-and-island-error branch November 19, 2026 17:09
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