Skip to content

fix: let an on_render hook pass its output to another component on a Vue page - #362

Merged
JuroOravec merged 2 commits into
mainfrom
fix/on-render-wrap-vue
Oct 25, 2026
Merged

JuroOravec merged 2 commits into
mainfrom
fix/on-render-wrap-vue

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

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_render hook that passes the output it received to another component failed, even for a component used on its own:

class Inner(Component):
    def on_render(self):
        result, error = yield
        return Frame(body=result)
UnsupportedPreparedView: render occurrence appears more than once

Frame printed result as another call of Inner, inside Inner's own output. The same error came from:

  • yield Frame(body=result);
  • return Shell(slots={"default": result});
  • an on_component_rendered hook that returns Frame(body=ctx.render).render();
  • a hook that returns result unchanged.

Fix

The hook means result as 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 Python Slot is called. It turns a component's own output into content that component wrote, as a nested template is, in two cases:

    • the printing component sits inside the author's output;
    • the printing component renders while the author's hook runs.

    A parent that prints Row().render() still gets an ordinary call of Row. A simple=True receiver 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:

    • the extra frame levels a cache replay adds;
    • a transparent author;
    • a decoration an extension added first, such as the debug outline, which it keeps.
  • 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:

  • The passed output carries no root markers of Inner's own on its top elements, as with any nested template.
  • Frame's root element is now also Inner's output root, so it carries both components' markers.
  • The visible effect: when Frame and Inner set the same css_data variable, the passed output inherits it from that root instead of using Inner's value directly.
  • The CHANGELOG has a line under Changed for this.

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:

  • where a fill's slot name comes from: the slot names and definitions a nested template compiles to, and keyed rows sharing one definition;
  • the slot calls the cache stores and checks: a cached nested-template author gives the same result on a hit, on its own, inside a template, and inside a slot fill;
  • a hook that returns its own result unchanged, on a page without Vue;
  • the same output printed twice staying an error.

The second commit adds TestVueCompilesReceivedOutputInItsComponent cases. Each compares the compiled definitions, the server HTML and the browser data with the nested template the hook's code means:

  • return and yield, on their own, inside a template, and inside a slot fill;
  • a cache hit;
  • a result passed as a slot;
  • return result;
  • an on_component_rendered wrap;
  • two wraps in a row;
  • a transparent author;
  • the component's own nested template next to the hook's output;
  • a parent printing Row().render(), which stays an ordinary call;
  • a simple=True receiver;
  • a decorated output;
  • results rendered and thrown away first;
  • an error boundary around output placed twice, with and without Vue;
  • the CSS-variables markers landing on the same elements with and without Vue.

The cases that expect the new behavior fail on the first commit.

Changed tests, all in TestWrapReceivedOutputInAComponent from #344. They locked Inner's marker on the passed output, which the maintainer's decision removes:

Test Change
test_the_kept_output_keeps_the_components_marker_on_its_own Renamed to test_the_passed_output_carries_no_marker_of_its_own, with the new HTML
test_the_kept_output_keeps_its_css_variables_marker Renamed to test_the_passed_output_inherits_css_variables_from_the_root, with the new HTML
The nested, yield, cache, on_component_rendered, two-wraps and side-by-side tests New HTML: no Inner marker on the passed <p>

Evidence

  • packages/py/citry/tests and packages/py/citry_ui/tests (-m "not e2e"): 9,537 passed on this branch (based on main b3491f0), with citry_core built from that base.
  • Vue render parity check over the whole suite (scripts/vue_render_parity/check.py): 1,013 pages compared, 0 mismatches, 0 Vue errors. 49 of those pages come from the tests in TestVueCompilesReceivedOutputInItsComponent and TestWrapReceivedOutputInAComponent.
  • Non-cargo phases, run by hand: ruff check, ruff format, mypy (and --platform linux), citry-client, protocol contracts, protocol Python copies, events protocol JavaScript, validators.
  • uv lock --check fails on main itself: chore: drop Python 3.10 support #336 removed tomli from packages/py/citry/pyproject.toml, but uv.lock still lists it. This PR changes neither file.
  • PR CI runs the cargo phases. This change has no Rust.

Known limits

These fail on main in the same way, so this PR leaves them as they are:

  • A transparent receiver cannot take the output on a Vue page ("selected direct fills were not consumed by their receiver call"). The nested-template reference, <c-tframe c-body="..." /> with a transparent tframe, fails the same way. The output reaches a transparent receiver unchanged.
  • An on_component_rendered hook that renders a simple=True component on its own, SimpleFrame(body=ctx.render).render(), fails on a Vue page with "render occurrence appears more than once" when ctx.render is 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.md says what passing result on means, with and without Vue, where the markers go, and the error modes.
  • The CHANGELOG entry from fix: let on_render pass its output to another component inside a template #344 now covers Vue, and a Changed line describes the marker change.

🤖 Generated with Claude Code

JuroOravec and others added 2 commits October 25, 2026 01:17
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]>
@JuroOravec
JuroOravec merged commit ead9648 into main Oct 25, 2026
14 of 27 checks passed
@JuroOravec
JuroOravec deleted the fix/on-render-wrap-vue branch October 25, 2026 08:42
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.

on_render: wrapping the hook's result in another component fails when nested

1 participant