Repository navigation
fix: let on_render pass its output to another component inside a template - #344
Merged
Merged
Conversation
…late An on_render hook that places the output it received inside its replacement, as in `return Frame(body=result)`, leaves two pieces of output marked with the component's render id: the output the hook received, and the replacement around it. When the component sat inside another component's template, serialization gave both the same placeholder key and raised "The same rendered component id was encountered more than once". An on_component_rendered hook that wraps ctx.render the same way hit the same error, as did either one once the component, or one around it, was cached. Serialization now gives a child its own placeholder key when frames around it have the same render id, numbered by how many of them do. A component's output can only sit inside that same component's output when a hook put it there, so this needs no flag on the render and survives a cache replay. The same output placed twice at one level, as in `Pair(first=result, second=result)`, still gets one key twice and is rejected, and a render that contains itself is rejected instead of looping forever. The received output keeps the component's root markers, such as the data-ccss-* attribute that css_data variables target. The tests lock the HTML of the component rendered on its own and inside another template and show the two agree. They also cover two wraps in a row, two components side by side, the cache, on_component_rendered, the development-mode id check, css_data, and the rejected cases. This covers pages rendered without Vue. The Vue path follows in its own change. Refs #173 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.
Refs #173. This is the first of two PRs: it fixes pages rendered without Vue. The Vue path, including standalone
str(Inner())on an interactive page, follows in a second PR that closes #173.Problem
An
on_renderhook can place the output it received inside another component:The output the hook received and the replacement around it both carry Inner's render id. When Inner sits inside another component's template, serialization gave both the same placeholder key and raised
RuntimeError: The same rendered component id was encountered more than once during serialization. Two related paths failed the same way:on_component_renderedhook that returnsFrame(body=ctx.render).render();Cache.enabledon Inner or on a component around it.Fix
serialize.pynow tracks the frames around the one it is building (_EnclosingFrames). A child frame whose render id matches some of those frames gets its own placeholder key, numbered by how many of them match. A component's output can only sit inside that same component's output when a hook put it there, so the rule needs no flag on the render, and it still works after a cache replay rebuilds the frames.What is still rejected:
Pair(first=result, second=result), on its own or nested: both copies get the same key;The received output keeps Inner's
data-cid-*marker and its other root markers, such as thedata-ccss-*attribute thatcss_datavariables target.Tests
TestWrapReceivedOutputInAComponentintests/test_on_render.pylocks the exact HTML on both the Rust and Python render paths:yielded wrapper, two wraps in a row, and two Inners side by side;on_component_renderedhook that wraps the output;Citry(mode="development")not reporting the keptidas repeated;css_datamarker on the kept output.16 of these cases fail on main and all pass with the change.
Evidence
packages/py/citry/testsandpackages/py/citry_ui/tests(-m "not e2e"): 9,497 passed, 53 skipped, 1 xfailed.scripts/check.py, run by hand: uv lock, ruff check, ruff format, mypy (and--platform linux), citry-client, protocol contracts, protocol Python copies, events protocol JavaScript, validators.Left for the second PR
render occurrence appears more than once./advanced/hooks/page still advises wrapping where the component is used. That advice stays correct until the Vue path works, so it changes with the second PR.🤖 Generated with Claude Code