Skip to content

feat(vue): one stylesheet tag for several apps, and experimental combine_assets() - #802

Merged
JuroOravec merged 2 commits into
mainfrom
feat/vue-style-link-apps
Nov 19, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
feat/vue-style-link-apps

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

(Opus 5.5)

Change C5 of the citry-django redesign, in two commits:

  1. The browser runtime accepts one served stylesheet tag that names several Vue apps.
  2. A new Experimental helper, combine_assets(), writes those tags. A host such as citry-django combines several renders' asset groups with it, without writing Citry's internal attribute itself.

What changes

The runtime (_vue/client.js, runtime.js rebuilt)

Citry writes each app's stylesheet tags with data-citry-vue-style-app="<app id>", and the runtime adopts a served tag only when that attribute names the app that is starting. Before this change N apps that load the same file needed N tags.

  • styleNamesApp now also accepts several app ids, distinct and 32 lowercase hex characters each, separated by single spaces.
  • Any other value names no app. On a mounted page the app requests the file itself; on a standalone page the app does not start.
  • Parsed lists are kept as Sets in a Map, which starts over past 64 lists.
  • Several apps can adopt one element, each in its own record. removeStyleElement takes it off the page only when no other record still holds it. This covers retiring unused styles, a failed served link, and the probe that rechecks a served link.
  • An app that the list names but that starts only after every app that adopted the tag has left finds no tag, and requests the file again on a mounted page. Islands on one page start together, so citry-django does not hit this.
  • runtime.js grows by 751 bytes before compression.

The helper (citry.combine_assets, Experimental)

groups = [
    combine_assets(r.runtime_assets for r in results),
    combine_assets(r.component_assets for r in results),
    combine_assets(r.app_assets for r in results),
]
  • Identical tags are kept once, where they first appear, so the runtime script appears once.
  • Stylesheet tags that are byte-identical apart from the app list become one tag naming every app, in first-seen order. URL, nonce, integrity and every other byte stay the ones Citry wrote.
  • Each app's configuration block and start script stay as they are, because they differ per app.
  • The app list is read only from the opening tag. A tag whose list the runtime would refuse is kept as written: a repeated id, uppercase, the wrong length, or text in a <style> body.
  • The order is deterministic: dicts in first-seen order, no set iteration.

The one-app server output is unchanged, and a test locks it, mounted and standalone. Docs: "Combine several renders" in asset-placement.md, the app_assets docstring, the Experimental list in versioning.md, reference.yml, and a changelog line under Unreleased that names this as groundwork for the citry-django integration.

Design (Mechanism 2)

Prior art.

  • _cut_separate_assets (serialize.py) builds the three groups; this helper does not change it.
  • The docs example deduplicated the runtime and component groups by hand with dict.fromkeys and kept every app tag.
  • citry.assets.dedupe deduplicates by equality but knows nothing of app ids.
  • Nothing in crates/ or the other packages combines several renders' tags.

API. combine_assets(groups: Iterable[SerializedAssets]) -> SerializedAssets, called once per group. It is a function in citry_render.py, beside SerializedAssets, and is exported from citry.

Alternatives considered.

  • combine_assets(renders) -> SerializedAssets for all groups at once: rejected. It would merge the three groups, and citry-django needs the component group apart for its on_page_assets hook.
  • combine_assets(renders) returning a new type with three groups: rejected, because it adds a type for no gain over three calls.
  • A method on SerializedAssets: equivalent; a function matches the name the maintainer suggested.

What would show it is wrong.

  • A merged tag that the runtime does not adopt; the browser test checks this.
  • A combined group that lost a nonce or integrity attribute, or that holds a tag none of its inputs held.
  • Output whose order changes between runs.
  • A host that needs a later render's stylesheet order kept. A tag several renders share stays where it first appears, which the docs now say. That matches how identical tags were already deduplicated.

Versioning

  • combine_assets is a new public name, marked Experimental and named in the Experimental list: a minor release.
  • data-citry-vue-style-app stays internal ("not covered" in docs/design/public_api_1_0_0_audit.md). Now Citry writes the list itself, so no package outside Citry reads or writes it.
  • A single id means the same as before. An older runtime never meets a list, because the page and the runtime come from the same citry package.
  • No contract version changes.

Security (Mechanism 7)

Places touched: markers for Citry's browser code, and addresses and keys the browser code takes from the server.

  • The list is written by Citry (combine_assets) from ids that match [0-9a-f]{32}, read only from each tag's opening tag; data cannot write the attribute name.
  • A merged tag is byte-identical to each input tag apart from the app list. A tag with a different nonce, integrity or attribute stays separate, and a test covers this. No tag moves between groups, because each call returns one group.
  • The runtime parses the list strictly with one anchored pattern, into Sets inside a Map, so __proto__ matches only itself.
  • A forged list cannot apply a stylesheet to another app or remove a tag another app holds. It can still make an app load the file again or not start, as before, and injected HTML would still have to guess the random 128-bit app ids.
  • result.security stays correct: CSP hashes cover element content, which the helper never changes. The docs now say a combined page needs every result's security.
  • docs/design/trust_boundaries.md row updated.
  • Mechanism 8: the reviewer checked the advisory survey's mXSS, hydration and marker, prototype, ReDoS, sanitizer-bypass and DOM-clobbering kinds. None applies as a hole.

Tests

  • JS (pnpm --dir packages/js/citry-client run check, including the generated-files canaries): 382 passed, 6 new. They cover the one-app and list matches, 12 malformed values, lookup by URL, a shared tag staying until the last app lets go, and the cache limit.

  • Python tests/test_serialize_separate_assets.py: 36 passed. They cover:

    • one-app output, mounted and standalone;
    • three renders combined: one runtime, one tag per file naming every app, every app script kept in order, nonce and integrity on every tag, and the same result when combined again or in steps;
    • merging only tags that differ in their apps alone;
    • 6 kinds of tag kept as written;
    • the list read only from the opening tag.
  • Browser (Chromium), tests/e2e/test_serialize_separate_assets_e2e.py:

    • two islands combined through combine_assets keep one stylesheet link, and both are styled and interactive with no errors;
    • a link naming both apps by hand, a link naming only one app, and a malformed list.

    On the old runtime the shared case fails with 3 links instead of 1.

  • Wider runs:

    • Full tests/e2e in Chromium: 658 passed. The one failure, test_preview_e2e, needs the full Chromium build, which is not installed here.
    • The citry unit suite: 14,753 passed. Two failures and some import errors need packages not installed here; both failures also fail on main.
    • scripts/validate.py: all passed.
    • ruff and mypy (also --platform linux) are clean on the changed files.

Benchmark

Threshold: flag more than 3% on any existing Vue or serialize benchmark under benchmarks/. Budget: about 10 minutes.

  • The serialize path is unchanged, so the serialize benchmarks cannot move. No existing benchmark covers the runtime lookup or the new helper, so I timed them directly.

  • Runtime lookup, in Node: 200 apps each look up their stylesheet among the page's tags, median of 41 runs.

    Case Before After
    200 one-app links 0.137 ms 0.156 ms
    1 link naming 200 apps n/a 0.017 ms

    The one-app lookup costs about 0.5 ns more per comparison, too small to see in an app's startup. Some busy-machine runs, before and after alike, came out near 0.4 ms; that is JIT state in the timing loop, not this change.

  • combine_assets on 200 islands, all three groups: 0.97 ms, against about 0.64 ms to serialize each island.

Review

Two independent reviews (technical, security, prose) found no security hole and no blocking bug.

Fixed during the review:

  • Runtime comments now state the failure on a standalone page correctly.
  • The parsed-list cache is capped.
  • The app list is read only from the opening tag.
  • A repeated id is kept as written.
  • The weak test cases are fixed.
  • The docs say "tag" where standalone pages use <style>, and describe the CSS order and security.
  • The changelog lines are folded together, and the docstring section order is fixed.

Left as is: there is no browser test of the standalone <style> merge; the runtime's lookup there is covered by the JS unit tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom

JuroOravec and others added 2 commits November 19, 2026 17:07
A host that combines several Vue apps on one page, such as citry-django
with one app per interactive region, can now keep one stylesheet link per
file: data-citry-vue-style-app may list the app ids separated by single
spaces. The runtime accepts only a list of distinct ids of 32 lowercase
hex characters, keeps parsed lists as Sets in a size-capped Map, and
removes a tag several apps adopted only when the last of them lets go.
Citry still writes one id per tag, so the one-app output and behavior are
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
combine_assets() takes the same asset group from several renders
serialized with deps_position="separate" and returns it with each shared
tag written once. Stylesheet tags of several Vue apps that are
byte-identical apart from the app id become one tag that names every
app, which the browser runtime accepts. The app list is read only from
the opening tag, and a tag it cannot read is kept as written. Tags keep
their nonce, integrity and first-seen order. 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 changed the title feat(vue): let one served stylesheet tag name several apps feat(vue): one stylesheet tag for several apps, and experimental combine_assets() Nov 19, 2026
@JuroOravec
JuroOravec merged commit 88d9973 into main Nov 19, 2026
10 of 20 checks passed
@JuroOravec
JuroOravec deleted the feat/vue-style-link-apps branch November 19, 2026 16:45
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