Repository navigation
fix: let an on_render hook pass its output to another component on a Vue page - #362
Merged
Merged
Conversation
The Vue fix for #173 compiles the output an on_render hook passes to another component the way a nested template is compiled. These tests pin the parts of that machinery the fix leans on, on the current code: - the slot name and definitions a nested template compiles to, and that keyed rows share one definition (where a fill's slot name comes from); - a cached nested template author giving the same result on a cache hit, on its own, inside a template, and inside a slot fill, where it renders inside the fill's slot call, which the cache stores and checks; - an on_render hook that returns the output it received still writing the template's HTML, on a page without Vue; - the same output printed twice on a Vue page staying an error. Refs #173 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Vue page On a page that uses Vue, an on_render hook that passes the output it received to another component, as in `return Frame(body=result)`, failed with "render occurrence appears more than once", even for a component used on its own. Frame printed the output as another call of Inner inside Inner's own output. A hook that returned `result` unchanged failed the same way, and so did an on_component_rendered hook that wraps ctx.render. The hook means the output as Inner's own content passed to Frame, which is what a nested template written in Inner's template means (`<c-frame c-body="..." />`), so it now compiles that way: Inner's definition fills a slot of Frame, and Frame prints that slot. - When a template or a Python Slot prints a component's own output, and the printing component sits inside that component's output or renders while that component's hook runs, `bind_received_output` turns it into content that component wrote (a `DirectNestedTemplateRender`). A parent that prints `Row().render()` still gets an ordinary call of Row. A simple=True receiver, which renders in its caller's context, joins the output in place. A transparent receiver, which has no Vue definition to take a slot, gets it unchanged, as before. - That content keeps the output's own component frame, so a cache entry stores it unchanged. The Vue capture compiles the parts inside it (`_projected_content`), also after a cache replay, for a transparent author, and around a decoration an extension added first. - The same output placed twice raises "encountered more than once" when the page is turned into HTML, after the render, so an error boundary does not hide it. Evaluating it again without placing it, such as a preview render the hook drops, still works. - A hook that returns `result` unchanged keeps it as the component's content, rather than nesting a second copy of the component. As the maintainer decided on #173, the passed output follows the nested-template rule on both paths: its top elements carry none of the component's own root markers. The other component's root element, which is now the component's root, still carries them. #344 had kept the component's marker on the passed output without Vue; that is changed here, and the tests that locked it now lock the new output. One visible effect: when both components set the same css_data variable, the passed output inherits it from that root instead of using the component's value directly. The tests compare each case with the nested template the hook's code means: the compiled definitions, the server HTML and the browser data, on its own, inside a template, inside a slot fill, from a cache hit, and through on_component_rendered. They also show that the CSS-variables markers land on the same elements with and without Vue. Fixes #173 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Oct 25, 2026
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.
Fixes #173. This is the second of two PRs. #344 fixed pages rendered without Vue; this one fixes Vue pages and makes the two paths agree.
Problem
On a page that uses Vue, an
on_renderhook that passes the output it received to another component failed, even for a component used on its own:Frame printed
resultas another call of Inner, inside Inner's own output. The same error came from:yield Frame(body=result);return Shell(slots={"default": result});on_component_renderedhook that returnsFrame(body=ctx.render).render();resultunchanged.Fix
The hook means
resultas Inner's own content passed to Frame. A nested template written in Inner's template means the same thing:<c-frame c-body="<p>inner</p>" />. So the output now compiles the way that nested template does: Inner's definition fills a slot of Frame, and Frame prints that slot.bind_received_output(_vue/direct.py) runs when a template prints a value and when a PythonSlotis called. It turns a component's own output into content that component wrote, as a nested template is, in two cases:A parent that prints
Row().render()still gets an ordinary call of Row. Asimple=Truereceiver renders in its caller's context, so it takes the output in place._projected_content(_vue/direct_capture.py) compiles the parts inside the output's component frame. It also handles:Placing the output twice raises "The same rendered component id was encountered more than once" when the page is turned into HTML. That is after the render, so an error boundary does not hide it. Rendering the output again without placing it still works: for example, a preview the hook throws away, or a slot the receiver calls to look at first.
return result(_replacement_parts) now keeps the output as the component's content. Before, it nested a second copy of the component inside itself.Markers: a change to #344's output
#344 kept Inner's
data-cid-*marker on the passed<p>. That decision assumed Inner's CSS would only reach the<p>through that marker, but Citry does not scope component CSS. The maintainer has since chosen to follow the nested-template rule on both paths:css_datavariable, the passed output inherits it from that root instead of using Inner's value directly.The static change is a small addition to
serialize.py. A frame whose render id belongs to a frame around it skips its own root markers.Tests
The first commit locks the parts of the nested-template code this fix reuses, on the code before the change:
The second commit adds
TestVueCompilesReceivedOutputInItsComponentcases. Each compares the compiled definitions, the server HTML and the browser data with the nested template the hook's code means:returnandyield, on their own, inside a template, and inside a slot fill;return result;on_component_renderedwrap;Row().render(), which stays an ordinary call;simple=Truereceiver;The cases that expect the new behavior fail on the first commit.
Changed tests, all in
TestWrapReceivedOutputInAComponentfrom #344. They locked Inner's marker on the passed output, which the maintainer's decision removes:test_the_kept_output_keeps_the_components_marker_on_its_owntest_the_passed_output_carries_no_marker_of_its_own, with the new HTMLtest_the_kept_output_keeps_its_css_variables_markertest_the_passed_output_inherits_css_variables_from_the_root, with the new HTMLon_component_rendered, two-wraps and side-by-side tests<p>Evidence
packages/py/citry/testsandpackages/py/citry_ui/tests(-m "not e2e"): 9,537 passed on this branch (based on main b3491f0), with citry_core built from that base.scripts/vue_render_parity/check.py): 1,013 pages compared, 0 mismatches, 0 Vue errors. 49 of those pages come from the tests inTestVueCompilesReceivedOutputInItsComponentandTestWrapReceivedOutputInAComponent.--platform linux), citry-client, protocol contracts, protocol Python copies, events protocol JavaScript, validators.uv lock --checkfails on main itself: chore: drop Python 3.10 support #336 removedtomlifrompackages/py/citry/pyproject.toml, butuv.lockstill lists it. This PR changes neither file.Known limits
These fail on main in the same way, so this PR leaves them as they are:
<c-tframe c-body="..." />with a transparenttframe, fails the same way. The output reaches a transparent receiver unchanged.on_component_renderedhook that renders asimple=Truecomponent on its own,SimpleFrame(body=ctx.render).render(), fails on a Vue page with "render occurrence appears more than once" whenctx.renderis undecorated, as on main. A simple component rendered on its own prints inside the transparent root of a standalone template, so it falls under the case above.Docs
/advanced/hooks/shows both ways to put the output inside another component, and that the output goes in one spot on the page.docs/design/component_on_render.mdsays what passingresulton means, with and without Vue, where the markers go, and the error modes.🤖 Generated with Claude Code