Repository navigation
fix: render a nested template printed twice instead of raising - #287
Merged
Merged
Conversation
A component that printed markup it received in a c-* attribute twice,
such as <div>{{ body }}</div><aside>{{ body }}</aside>, failed with
"deferred part vanished from its .parts list before resolution" after
rendering the components inside twice for one call. Both prints shared
one parts list, and the render queue (the loop that renders child
components after their parent's template) queued its placeholders twice.
Each print now renders on its own, as each outlet of a slot does: the
first print takes the render made where the attribute was evaluated, and
every later print renders the template again in the same scope and slot
fill call. The render queue also refuses to enter one parts list twice,
within one component's output, while it still holds unrendered
components, so a slot called once in Python whose result one template
prints twice fails with an error that names the component before any
component inside it renders. A copied list or one value printed by two
components is not caught yet.
The call order record for nested_template_printed_twice changes from an
error after Row a0 rendered twice to both prints rendering their rows.
Fixes #273
Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
added a commit
that referenced
this pull request
Oct 24, 2026
…mponents render twice A slot's result that a component printed and also passed to a child that printed it rendered the slot's components twice and then failed with "deferred part vanished", or, with the two prints in the other order, failed at serialization with "The same rendered component id was encountered more than once". #287's check remembered the parts lists it entered only for one scan, which covers one component's output. Every scan of one render queue run now shares a record (_QueueScans) of the parts lists entered and the placeholders queued. A scan raises the "printed in more than one place" error, naming the component whose output prints the content the second time: - when it reaches a list again that still holds a component waiting to render; - when it reaches a list again whose components already rendered, simple="vue" output included, from any component's output (new message: they can appear only once on the page); - when it would queue a placeholder again from another list, as a copy of a parts list does. A list with no components is still skipped, and a placeholder repeated within one list still renders at each position. When an on_render hook returns or wraps the output it received, the record forgets that output before the replacement is scanned, since the output moved rather than being printed twice. The locked test for a copied row list now expects the new error before any row renders twice. The design doc says what the check covers and what it does not (content printed inside a nested run). Fixes #295 Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
added a commit
that referenced
this pull request
Oct 25, 2026
…mponents render twice A slot's result that a component printed and also passed to a child that printed it rendered the slot's components twice and then failed with "deferred part vanished", or, with the two prints in the other order, failed at serialization with "The same rendered component id was encountered more than once". #287's check remembered the parts lists it entered only for one scan, which covers one component's output. Every scan of one render queue run now shares a record (_QueueScans) of the parts lists entered and the placeholders queued. A scan raises the "printed in more than one place" error, naming the component whose output prints the content the second time: - when it reaches a list again that still holds a component waiting to render; - when it reaches a list again whose components already rendered, simple="vue" output included, from any component's output (new message: they can appear only once on the page); - when it would queue a placeholder again from another list, as a copy of a parts list does. A list with no components is still skipped, and a placeholder repeated within one list still renders at each position. When an on_render hook returns or wraps the output it received, the record forgets that output before the replacement is scanned, since the output moved rather than being printed twice. The locked test for a copied row list now expects the new error before any row renders twice. The design doc says what the check covers and what it does not (content printed inside a nested run). Fixes #295 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #273
What was wrong
A page can pass a component markup written in a
c-*attribute (a nestedtemplate). When that component printed it twice, the render failed:
Before it failed,
Rowrendered twice for the one call, so itstemplate_data()and other callbacks ran one extra time.Citry renders the nested template once, where the page evaluates the
attribute, into a
CitryRenderwhose parts hold a placeholder forRow.Each
{{ body }}wrapped that same render (bind_nested_template), soboth prints shared one parts list. The render queue's scan
(
_scan_deferred_parts) reached that list once per print and queued theplaceholder twice. The second task rendered
Rowagain and then foundits place already taken.
The fix
Each print now renders on its own, as each outlet of a slot does. A slot
runs its fill again for each
<c-slot>outlet, so the nested template nowdoes the same for every print after the first:
nodes/__init__.py(TemplateHtmlAttr.resolve): with the render madeat the attribute, the value now carries a
render_againfunction. Itrenders the template's compiled body again with the same context, inside
the same slot fill call (
direct_execution_scope) as the first render._vue/direct.py:UnboundNestedTemplateRenderrecords whether a printhas taken the first render.
bind_nested_templategives the first printthat render and calls
render_againfor each later print. Each printstill gets its own execution index, so the browser data has one fill and
one
Rowoccurrence per print.component_render.py(_scan_deferred_parts): the render queue (theloop that renders child components after their parent's template)
scans each component's output for the components still to render. The
scan now remembers the parts lists it has entered. When it reaches one a
second time, it skips the list if every component in it has rendered.
Otherwise it raises a
RuntimeErrorthat names the component path,before any component in the list renders twice. For example, a slot
called once in
template_data(), whose result the template printstwice, now gets this error in place of the "vanished" one, before any
component inside it renders. A component
element built in Python (
Row(title="A")) printed twice still rendersonce per print, as the issue's table shows.
child's), the new error skips
on_rendererror handling, as thenesting-depth error does and as the old "vanished" error did. It is a
mistake in the code, and a fallback would hide it. When it is in output
that an
on_renderhook yielded or returned, it takes the same route asany other error in that output: to the component's own hook (if it
yielded) or extensions first, then to its ancestors. The
_scan_deferreddocstring anddocs/design/component_rendering_defer.mddescribe the rule.
What the new check does not catch
The scan compares lists by identity, and it remembers them only while it
scans one component's output. Two shapes of the same mistake still render
a component twice and then raise the old "vanished" error:
test
test_call_run_tasks.py::test_a_row_list_printed_again_after_its_first_row_renders_only_the_unplaced_rowslocks that behavior;
that a template prints and also passes to a child that prints it.
Catching these needs the render queue to remember lists across scans.
That is left for a follow-up issue.
Why render again, rather than copy the first render
The issue suggested giving each print its own copy of the parts. A copy
would have to know every kind of part a template can leave for the render
queue: placeholders, the rows of a
<c-for>loop that point into theirlist,
<c-if>blocks, a<c-slot>inside the markup (which would need anew slot fill call), and simple components. It would also have to change
with every new part kind. Rendering again handles every one of those,
because it runs the same code the first render ran, and it matches what a
slot does.
The cost is a behavior to know about: the markup's expressions run once
for each print.
c-title="label()"with a counter givesn1andn2,which is what a slot fill does too. The first print is still the render
made at the attribute, so a value printed once renders exactly as it
did before, and its callbacks run in the same order. One difference from a
slot remains: the first print's expressions run when the page evaluates
the attribute, and later prints' expressions run when the receiver prints
them, so a value that changes in between shows up only in later prints.
The changed call order record
This changes one locked record on purpose.
nested_template_printed_twicein
tests/test_call_run_order.pyputs a four-row loop in a nestedtemplate that
Cardprints twice. Its record used to endRow a0, Row a1, Row a2, Row a3, Row a0 -> RuntimeError: rowa0rendered a second time, then the error. It now records
Row a0, Row a1, Row a2, Row a3, Row a0, Row a1, Row a2, Row a3 -> rendered.In the fixture, the second print's four rows follow, each with its own
render id, then the context merges for the second print and the parents,
then the hydrated and static serialize records. The old record locked the
bug. I rewrote
fixtures/call_run_order.jsonwithpython -m tests.test_call_run_order --write. It is the only case whoserecord changed, and the other 43 cases keep theirs on both render paths.
Tests
test_vue_nested_template_projection.py:Rows with different render ids, the expressionevaluated once per print, two distinct fills in the page's browser
definition, and one
Rowoccurrence per print;manifest has five occurrences (Document, Page, Receiver, and two
Rows);c-for: threeRows, three ids;Rows;c-foron the page: each Twice's second print stillsees the loop pass it was written in (
a, a, b, b);<c-slot>, printed twice on a page Vue hydrates: thewriter's fill renders once per print, with five occurrences in the
manifest;
on_render, whichreplaces the output with its fallback.
All of them fail on
main.test_deferred_render.py: a slot result printed twice raises the newerror, naming
Page > Twice, andRow'stemplate_data()never runs.It fails on
main, whereRowrenders and then the "vanished" erroris raised.
The tests that call
wrap_nested_templatedirectly pass the newrender_againargument.Every new test runs on both render paths (
render_path). The wholecitrytest suite passes with and without--python-render-path.The Vue render parity check over the touched test files compared 26
pages: 0 mismatches.
Docs:
docs_site/content/syntax/nested-templates.mdanddocs/template-syntax.mdsay that inserting the value more than once giveseach place its own render, with the expressions running once for each
place, and the docs page says when each place reads them.
scripts/check.py --profile faston 31cbb69:"status": "PASSED"(every phase, including pytest and the Vue render parity check). mypy with
--platform linux:no issues.
This branch starts from
main. It does not touch the files #271's fixchanges, apart from a separate
CHANGELOG.mdentry, so the two merge ineither order.
🤖 Generated with Claude Code