Repository navigation
feat(vue): accept HTML from templates with foreign spans as static blocks - #803
Merged
Merged
Conversation
…ocks
An interactive component can now hold HTML that Citry did not compile,
such as a fill written in a template whose {% %} tags Django renders. The
Vue writer joins each plain string part with the following parts that
need no Vue into one opaque HTML record, which the browser inserts as a
static node and never compiles. Static components inside keep their root
markers, and their stylesheets load with the component that holds the
block. An Events Render compiles such templates for static output too.
A block that is not a complete fragment, that has an interactive
component inside one of its elements, or that holds <script> or
<noscript> raises an error that names the case.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
Refuse Vue attributes that the author wrote in a template with foreign spans when its output reaches a Vue app, since the static block would drop them silently. A static component that takes a fill now joins the block, a <c-mark> keeps its Vue occurrence, and the "component inside an element" message is used only when a part that needs Vue ends the block. The script refusal and the docs now say the script would run only on a first hydrating load. New tests cover these cases, each spelling of <script>, line breaks at the app root, and a mounted (not hydrated) page. 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)
An interactive component can now hold HTML from a template with foreign spans (tags another engine renders, such as Django's
{% %}tags). This works on the serialize path and in an EventsRender. Before, such HTML raisedunsupported typed render part: strorprepared Vue rendering does not yet support foreign template spans. This is change C3 of the citry-django redesign (citry-django/docs/vue-redesign.md). It builds on #800 and #801.Plan
Prior art
component_render.py_get_compiled_template(origin/main 3053-3063) and_compile_nested_template(3290-3297). A template with foreign spans compiles for static output, so its parts are plainstr. Undervue_render_active()(Events) these functions raised._render_bodyrefused raw strings through_BodyFrame.direct_prepared(3417, 3456, 3517), and so did_vue/capture.py::_validate_prepared_render(1503)._vue/direct_capture.pypart loop. AMarkupvalue becomes one opaque HTML record (3081-3120). The record is checked byreject_cross_boundary_htmlandreject_noscript_in_opaque_html(opaque_html.py:36-118), with refusals under svg/math and text-only elements. The browser inserts it withcreateStaticVNode(client.js<citry-opaque-html>), and the template only holds<citry-opaque-html :record="$citryPrepared.opaqueHtml.key">. A plainstrfell through tounsupported typed render part(3590)._ignored_contents_html(#c-ignore/v-precontents) writes typed parts as static HTML. This change reuses its rules for which bindings need Vue._vue/events.py(857-1116). Stylesheet owners come fromrender_to_occurrence. An unknown render id falls back to the root occurrence. Opaque records already get the settledsecurity_javascript/security_cspscans (965-988).CitryRender.needs_browser_runtime()(C2, feat(serialize): return asset tags apart from the HTML with deps_position="separate" #801) answers "does this subtree need Vue".Chosen design
str,write_static_html_runbuilds a run. It joins the string with every following part that_static_part_htmlcan write as static HTML: more strings,Markup, static typed parts, and static component renders. Static components keep their root markers (css_data()markers included). A part that needs Vue raises_NeedsVue, which ends the run, and that part is walked as usual.markup, so the browser checks it for<noscript>again.<c-mark>ends the run, because aRenderfinds a mark by its occurrence.reject_cross_boundary_html);<script>(newreject_script_in_opaque_html, which also catches uppercase and svg/template spellings) and<noscript>;Alternatives rejected
<li>{% trans %}<c-icon/></li>would split across blocks and be refused.What would show the design is wrong
Common Django templates that put an interactive component inside a Django-written element, inside an interactive component. Each one raises the refusal. Counting them while migrating the citry-django test project measures this.
Deviations from the design
<noscript>and Vue attributes in the author's own template with foreign spans are refused too. The second keeps the design's rule that an interactive component's own template with Django tags raises: it raised before, and without this check it would now fail silently.Security (Mechanism 7)
Places touched:
Who writes the input: the template author and app code. The other engine escapes the request values it writes. The HTML reaches the browser only as data, in the opaque record, never as Vue template source. Tests use mustache,
v-html,@click,:titleand#defaultstrings, and the browser test checks that none of them runs or renders.security_csp="strict"refuses an inline handler in the block, andsecurity_javascript="warn"reports it.The independent reviewer probed these routes in Chromium:
Render;<!--[-->,data-cid-*,citry-opaque-html,<template c-render-id>,citry-vue-*ids, and a config<script>;<select>,<tbody>text,<p><div>,<plaintext>,<xmp>, CDATA, svg/math);__proto__keys.It found no hole. Pages it cannot adopt fall back to
data-allow-mismatchrebuilds. Firefox and WebKit were not tested. The Mechanism 8 survey kinds checked: template-inj, trusted-shape, sanitizer-bypass, xss-rawtext, hydration, ssr-serialize, mxss, dom-clobber, proto. None was found.docs/design/trust_boundaries.mdhas a new row. Thedocs/security/reviews/record follows after merge.Fixed during the review:
DirectSlotRenderwas missing from the flattener, so a static component with a fill inside a Django element was refused.Versioning
Input that raised now works, so this is a minor release. No new public names:
reject_script_in_opaque_htmlis private and the foreign-span hooks are already Experimental. Input that already worked behaves the same. Raw strings that were refused before, for example from extension hooks, are now accepted as trusted HTML. This matches what the static serializer already does with a rawstr. The changelog line is under Unreleased and says it prepares the citry-django integration.Benchmarks
The question: does the path for templates without foreign spans slow down by more than 3%? Budget: about 10 minutes. Base is origin/main (
git archive) and head is this branch. The runs alternate in fresh processes, with the PyPI release build of citry-core 2.1.2. The client scenario runner (benchmarks/client_scenario.py) is stale, because it uses the removedc-$c-props. So the Vue serialize rows use the large and small benchmark fixtures (str(ProjectPage), a hydrating Vue page).test_benchmark_citry), median of 11 × min of 15test_benchmark_citry_small), median of 11 × min of 40slot_renders.py --scenario filled, min / medianslot_renders.py --scenario fallback, min / medianAll are within noise and under the 3% threshold.
Checks
ruff check,ruff format --check, and mypy onpackages/py/citry/citry, also with--platform linux: clean.tests/test_vue_static_foreign_html.py: 26 passed. These cover the fill cases, the static component with a fill or<c-provide>, marks, the EventsRender, each refusal, Vue syntax injection, and the CSP and JavaScript checks.tests/e2e/test_vue_static_foreign_html_e2e.pyin Chromium: 2 passed (hydrated and mounted). Each run hydrates or mounts the page, checks that injected Vue syntax stays inert, and runs two Events renders.tests/test_vue_migration_coverage.py: one test updated to the new contract (raw strings are kept).🤖 Generated with Claude Code
https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom