Repository navigation
fix(vue): accept on an event what the page accepts for static HTML, and name each refusal - #807
Merged
Merged
Conversation
…nd name each refusal
An Events Render now checks its tree with the Vue writer's own
is_prepared_leaf_part, the function the writer uses to decide which
parts it accepts. So the Markup part that each {{ }} of a template with
foreign spans writes renders on an event as it does on the page, and
the writer's checks on the block still apply on both paths.
Each refusal of HTML that Vue would insert as a static block now raises
a named, Experimental subclass of StaticHtmlError that also subclasses
the ValueError or TypeError raised before: IncompleteStaticHtmlError,
VueInsideStaticHtmlError, ScriptInStaticHtmlError,
VueSyntaxInStaticHtmlError and StaticHtmlPlacementError.
When a block such as Django's {% if %} or a <c-for> loop wraps an
interactive component inside an element of such HTML, the refusal now
names the component and says to move it out of the element.
Vue syntax in a template with foreign spans is now refused for every
template whose output reaches a Vue app, read from the template each
render ran: this adds the template passed to render_template(), fills
written in it, and transparent components, which were skipped silently.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
- A static block now joins only a plain string or Markup, the same parts is_prepared_leaf_part accepts, so a str subclass after a plain string is refused on the page as it is on an event. - The Markup and <c-raw> placement refusals raise StaticHtmlPlacementError too. - The Vue syntax refusal says the attribute would stay a plain attribute that Vue never compiles, and that an Alpine.js short form such as @click is refused too, while its long form x-on:click is not. - Changelog: an Events Render with a Markup value, such as slot content from Python, no longer fails (a fix to 1.0.x behaviour). - One lru_cache on the template scan, and accurate comments and docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom
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)
Fixes four gaps in the static HTML feature from #803, which citry-django's step 6 found. citry 1.1.0 is waiting on this PR.
Changes
A server event crashed on one template shape. In a template with foreign spans, each
{{ }}writes aMarkuppart. The page accepted it, but an EventsRenderrefused it with "unsupported raw output: Markup". Now the Vue writer decides which parts it accepts with one function,is_prepared_leaf_part. The event's pre-check (_validate_prepared_render) calls that function, and so does_static_part_htmlwhen it joins a static block, so the two paths accept the same parts. The writer's checks on the block (fragment,<noscript>, svg and text-only parents) still run on both paths, and a test shows an event refuses the sameMarkupvalue the page refuses. Joining a static block now takes only a plainstrorMarkup, so astrsubclass is refused there as everywhere else.Named Experimental exceptions. A refusal now raises a subclass of
StaticHtmlError, and each subclass also subclasses the built-in type Citry raised before:IncompleteStaticHtmlError(ValueError)VueInsideStaticHtmlError(ValueError), with.component_nameScriptInStaticHtmlError(ValueError), with.tagVueSyntaxInStaticHtmlError(TypeError), with.component_nameand.syntaxStaticHtmlPlacementError(TypeError), which also covers theMarkupand<c-raw>placement refusals.They are exported from
citryand listed as Experimental inversioning.mdand inreference.yml.Clearer "inside an element" message. Sometimes a render that is not a component wraps the component, such as a Django
{% if %}block or a<c-for>loop. The message used to say "A part that needs Vue" in that case. Now it names the component and says to move it out of the element, or to write the element and the tags around it in Citry syntax.@clickwas not checked in some templates. The refusal used to read only the template of the component that owned the static block. Now_refuse_vue_in_static_templateswalks the whole tree before assembly and reads the template that each render ran (CitryContext.template_record). That adds three cases that were not checked before: the template passed torender_template(), fills written in it, and transparent components (found with Mechanism 3). The message says an Alpine.js short form such as@clickis refused too, and that its long form,x-on:click, works.Tests
test_vue_static_foreign_html.pyandtest_vue_prepared_capture.py. Eight of the new tests fail on the base, through a shim that maps the new names to the built-in types, and pass here. Thestrsubclass test was added during review, from the reviewer's probe on the base.--platform linux. ruff check and ruff format pass.vue-islands) run against this branch: 447 passed, with 2 expected failures. Its strict xfail for gap 1 now passes (XPASS(strict)). Its gap 3 test expected the old generic message and now gets "Tick needs Vue, ...", because Citry now names the component. citry-django was not edited.Benchmark
Base and head ran alternately, each sample in a fresh process.
benchmarks/slot_renders.py --scenario filled, 9 runsSecurity (Mechanism 7)
An independent reviewer compared every route that a
Markupor plain-string part can take on the page and on an event: a static run, aMarkuppart on its own, a slot fill, svg and text-only parents,#c-ignoreandv-precontents,<c-raw>,simple='vue'rows, and cached renders. Every route is safe; it found no hole. The template walk for gap 4 has no bypass through the payload cache, call runs, projections, nested templates oron_renderresults. Output of a template with foreign spans is never stored in the render cache.Versioning
C3 (#803) is unreleased and ships in 1.1.0, so the new refusals do not break anything users have. The new classes subclass the old built-in types, so existing
except ValueErrorandexcept TypeErrorclauses keep working. One line under### Fixescovers a change to 1.0.x behaviour: an EventsRenderno longer fails when aMarkupvalue, such as slot content passed from Python, reaches it. All of this fits the 1.1.0 minor release.🤖 Generated with Claude Code
https://claude.ai/code/session_01KUhrHaXagmW5ZxpRAMwyom