Repository navigation
feat(serialize): return asset tags apart from the HTML with deps_position="separate" - #801
Merged
Merged
Conversation
…tion="separate" Code that puts several Citry renders on one page (citry-django renders each interactive region as its own Vue app) can now ask serialize_result() for the HTML without asset tags and get the tags back in three groups on SerializedRender: runtime_assets, app_assets and component_assets. Each group is a SerializedAssets with css and js tuples. The tags are placed exactly as "smart" places them, wrapped in comments that carry a per-call random value, and cut out only after the nonce, integrity, CSP and JavaScript checks, so they match the tags "smart" writes. Vue hydrates the HTML as with "smart". CitryRender.needs_browser_runtime() tells whether a render becomes a Vue app when serialized on its own, and its docs state that a child component's render may be serialized on its own before its parent. Both are Experimental and listed on the versioning page. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
…eview findings A child component's render that holds slot content written outside it cannot be the root of its own Vue app, because Vue has no owner for that content there. The contract now says so, and serialize raises TypeError with a message that names the case instead of an internal ownership error. Without mounted routes, Citry's inline component code goes to runtime_assets with the runtime, so component_assets holds only ordinary tags. The docs page, docstrings and changelog line are rewritten after an independent review and a cold read, and new tests cover hook scripts, the path without mounted routes, JavaScript forbid mode and the slot-content refusal. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
…go integration Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
This was referenced Nov 19, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(Opus 5.5)
Adds
deps_position="separate"andCitryRender.needs_browser_runtime(), both Experimental, for citry 1.1.0. They are items C1 and C2 of the citry-django Vue redesign. citry-django will render each interactive region of a Django page as its own Vue app and write each shared asset tag once per page.What changes
serialize_result(deps_position="separate")returns the HTML with no asset tags. The tags come back in three new fields ofSerializedRender, each a newSerializedAssets(css, js):runtime_assets: Citry's own code that every app shares (the runtime, extension scripts, preload hints, and the inline component code when no web integration is mounted);app_assets: one app's stylesheets, configuration data and start script;component_assets: every other tag."separate"exactly as it does with"smart".deps_strategy="fragment"with"separate"raisesValueError. With"ignore", every group is empty. A hook that changes a returned tag makes serialize raiseRuntimeError.CitryRender.needs_browser_runtime()returns whether a render needs the browser runtime. Its docs state the contract: a child component's render may be serialized as its own app before its parent, as long as the child holds no slot content that a component outside it wrote. Such a child raisesTypeErrorwith a message that says so.Plan
Prior art (line numbers on
origin/main, 497da50):serialize.py:651serialize_render_resultruns one Vue analysis per call, andserialize.py:1148returnsSerializedRender(html, security)with no asset data.deps_position == "smart"atserialize.py:247,:769and:785, and at_vue/serialization.py:1284and:1522.ext/dependencies/emission.py:450(_place_dependency_html, through_insert_defaultat:1334) and_vue/serialization.py:638(VueSerializationPlan.finalize, with preload hints from_insert_script_preloadsat:237).context.extraare cleared and restored throughSERIALIZATION_NOTE_KEYS(emission.py:75).analyze_vue_serialization(_vue/serialization.py:903) already gives the same "needs Vue" test that serialize uses.Chosen design.
"separate"places every tag exactly where"smart"would. Each tag is wrapped in a comment pair that carries a random value chosen for that one call. The wrapped tags stay in the page through the Vue host check, the nonce and integrity pass, and the CSP and JavaScript checks. Only afterscript_security.finalizeare they cut out and grouped. So the returned tags, their attributes andresult.securityare identical to what"smart"writes, and the hydration checks accept"separate"wherever they accept"smart".Alternatives rejected.
data-citry-vue-*attributes. The design rejects this because those attributes are not covered by the 1.x promise."smart"writes and checks. Every check would need a second code path, and a check on one path only is a hole on the other (Mechanism 7 step 3).Result that would show the design is wrong. Either of these:
"smart"writes is missing from the groups or differs from them, orresult.securitydiffers;test_returned_tags_are_the_tags_smart_insertschecks the first case with a nonce, with integrity and under strict CSP. The reviewer also compared 576 combinations of options. The browser test checks the second case.Benchmark
Decision: does this slow existing pages? Threshold: flag any existing serialize scenario more than 3% slower. Budget: about 10 minutes. Each scenario renders and serializes with the default position, timing the median of N calls in a new process. Each one ran 11 times, alternating
origin/mainand this branch. Machine: Apple Silicon, Python 3.12, citry-core 2.1.2 wheel from PyPI.test_benchmark_citry.py)test_benchmark_citry_small.py)An earlier run that compared
mainwith an identical copy of itself varied by up to 2.8%. No scenario is slower by more than that noise. For comparison, serializing the island with"separate"took 0.44 ms against 0.57 ms with"smart". With"smart"and no<head>, Citry still parses the page to look for one before writing the preload hints.Security (Mechanism 7)
This change touches:
An independent reviewer tried to break each route:
"smart".omit,forbid, warn findings and strict refusals match too. Two apps ran under a real strict CSP in Chromium and Firefox.No hole was found. The reviewer also ran the Mechanism 8 advisory-survey pass and found no bug kind introduced.
Versioning
New Experimental API, so it ships in a minor release (1.1.0).
DepsPositiongains a value, andSerializedRendergains three trailing fields with defaults. Construction with two arguments, keyword construction andmatchpatterns keep working. Two things do change:dataclasses.fields()andastuple()now return five items.SerializedRenderpickled under 1.0.x and unpickled under 1.1.0 lacks the new fields.An extension that branches on
OnSerializeContext.deps_positionsees"separate"; tags it inserts stay in the HTML, as the docs say.Tests
test_serialize_separate_assets.py: 25 tests. They cover parity with"smart"(default, nonce, integrity, strict CSP), the groups, hydration, a document's placement tags, static pages, hook scripts, the path without mounted routes,ignore,fragment, JavaScript warn/omit/forbid, a forged wrapper, a hook that edits a tag,needs_browser_runtime(), a child serialized before its parent, and a child with slot content from outside.e2e/test_serialize_separate_assets_e2e.py: two separate islands share one runtime on one page. Both hydrate (the elements the server wrote stay) and run their own handlers. It passes in Chromium, Firefox and WebKit.test_vue_migration_coverage.pymatched the old internal text of the slot-content error; it now matches the new message.origin/mainin this environment (a pydantic and a tzdata test). The related Vue/serialize e2e suites pass in Chromium. ruff, mypy, mypy--platform linuxandpython -m docs_site build-checkare clean.🤖 Generated with Claude Code
https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom