Repository navigation
fix: catch content printed by a component and its child before its components render twice - #333
Merged
Merged
Conversation
JuroOravec
force-pushed
the
fix/deferred-parts-printed-twice
branch
from
October 24, 2026 22:25
5d8d31f to
bd3f084
Compare
…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]>
The errors for content printed in more than one place now say how to show it in several places: pass the slot itself instead of calling it, or a component element such as `MyComponent()` instead of `MyComponent().render()`. A slot or an element renders again at each place that prints it, so each place gets its own copy of the components inside. An on_render hook has no slot or element to pass, so the advice also says to place the output the hook received only once. A finished output such as `Row().render()` printed twice is caught later, when the page is serialized, because each print wraps it in a new render. Serialization's error for it now reads "One rendered output is printed in more than one place on the page" with the same advice, and the Vue capture raises that same RuntimeError on a page that uses Vue, where it used to raise a TypeError, "render occurrence appears more than once". A render that contains itself gets its own message, since nothing is printed twice there. The slots page gets a section that shows the first try, why it fails, and the fix, and the rendering page's warning links to it. Refs #295 Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec
force-pushed
the
fix/deferred-parts-printed-twice
branch
from
October 25, 2026 00:06
bd3f084 to
fdcde67
Compare
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 #295
What changes
Here a component prints a slot's result itself and also passes it to a child component tag that prints it too:
That used to render the slot's components twice, then fail with "deferred part vanished". With the two prints in the other order, it failed at serialization with "The same rendered component id was encountered more than once". The check from #287 remembered the parts lists it had entered for one scan only, and a scan covers one component's output.
Now every scan in one run of the render queue shares one record of the parts lists it entered and the placeholders it queued (
_QueueScansincomponent_render.py). A scan raises the "printed in more than one place" error, naming the component whose output prints the content the second time, in three cases:simple = "vue"output included, from any component's output. New message: "...the components inside it can appear only once on the page...".What still works as before:
on_renderhook returns, yields or wraps the output it received, the record forgets that output before the replacement is scanned, because the output moved rather than being printed twice. A replacement that holds the output twice still raises.Known limit, stated in
docs/design/component_rendering_defer.md: a nested run keeps its own record. One example is a component placed in an expression,{{ el }}whereel = Show(body=body). Content printed both inside such a nested run and in the outer one is not caught. It still fails at serialization when it holds an ordinary component.The errors say what to do (second commit)
The maintainer agreed to keep the error and asked for it to suggest the fix. The second commit adds that:
_PRINT_IN_MANY_PLACES_ADVICEincitry_render.py): "To show it in several places, pass the slot itself instead of calling it, or a component element such as MyComponent() instead of MyComponent().render(): each place that prints a slot or an element renders its own copy. In an on_render hook, place the output the hook received only once." A slot or an element renders again at each place that prints it, so each place gets its own copy of the components inside. I checked this with and without Vue.Row().render()printed twice is caught when the page is serialized, because each print wraps it in a new render. That serialization error now reads "One rendered output is printed in more than one place on the page, so the components in it would appear more than once." and carries the same advice. On a page that uses Vue, the Vue capture now raises that sameRuntimeError. It used to raise aTypeError, "render occurrence appears more than once". Nothing catches that error by its type: everyexcept UnsupportedPreparedViewwraps a different call./concepts/slots/has a new section, "Show a fill twice". It shows the first try, why it fails, and the fix: pass theSlotitself. It also covers the dict form, typing a child's input asSlot, and passing an element instead of its rendered output. The rendering page's warning links to it.Tests
New tests in
tests/test_deferred_render.py, each run on both render paths:on_renderreturn, yield and wrap of the received output, which render;simple = "vue"slot content printed by a component and its child, which raises.The new cases that expect an error fail on main. The text-only and on_render cases guard against false positives; the on_render ones also caught a false positive in this PR's first version.
The second commit adds tests, also on both render paths:
The message tests fail without the second commit.
Existing tests changed:
test_call_run_tasks.py::test_a_row_list_printed_again_after_its_first_row_renders_raises_before_rendering_a_row_twice(was..._renders_only_the_unplaced_rows)test_on_render.py(two tests),test_ext_debug.py::test_decorated_component_root_cannot_be_reused_twicetest_vue_direct_relationships.py(the duplicate#c-keytest)Evidence
Run locally on this branch, rebased onto origin/main 2640d24, with a citry_core built from main b3491f0:
-m "not e2e"): 9,611 passed. Two cases fail,test_render_body_snapshots.py::test_an_error_three_levels_deep_matches_the_snapshot[rust]and[python]. They fail the same way on origin/main with that citry_core, because main has newer Rust (fix: parse and compile deeply nested templates on any thread without crashing #343, fix: leave Vue string literals holding a lone surrogate to the browser #349, perf: render nested control flow without one Python call per level #356). PR CI builds fresh Rust;--platform linux;PR CI runs the cargo phases. This change has no Rust.
Review
An independent adversarial review ran twice on each commit, each time with a prose pass. A separate first-time reader also read the new docs section twice. All findings are folded in:
on_renderhooks that keep their output;simple = "vue"output not counted as components;on_renderhook;Slotsclass.Known gap, already there before this PR: a
simple="vue"component'sRow().render()printed twice withdeps_strategy="ignore"or"simple"raises no error and prints twice.🤖 Generated with Claude Code