Skip to content

fix: render a fill passed on through components in the running body loop - #522

Merged
JuroOravec merged 1 commit into
mainfrom
fix/render-forwarded-fills-in-the-running-loop
Oct 28, 2026
Merged

JuroOravec merged 1 commit into
mainfrom
fix/render-forwarded-fills-in-the-running-loop

Conversation

@JuroOravec

Copy link
Copy Markdown
Member

Part of #299 (PR A of 2; PR B covers simple='vue' components nested more than 16 levels deep).

What changes

A component that passes its slot content on with <c-fill><c-slot /></c-fill> used to start a new run of the body renderer for every component in the chain. That cost about 10 Python frames per link, so a chain of about 100 raised RecursionError.

The slot now hands a plain template fill to the body renderer that is already running. It does this through the generator it already uses for its own fallback (SlotNode._slot_steps), which keeps the same scopes, runs the same checks, and wraps the result the same way as the Slot call it replaces. Any other fill still goes through the Slot call: a Python function, a Slot subclass, a fill from another session, or any fill while code has replaced Slot.__call__ or the template content's __call__ or _render.

Still not fixed: content passed on through an expression. Content passed on as {{ content }}, where template_data() returns slots["default"], or through a Python slot function that calls the fill, still costs about 11 to 12 Python frames per link (11 measured on CPython 3.14.9). Such a chain raises RecursionError somewhere between 90 and 100 links. The docs page (syntax/index.md) and the changelog entry both say so and give about 80 components as the safe figure.

Frames, before and after (CPython 3.14.9, both render paths)

Case Before After
test_render_depth_frames chain, 8 vs 64 links 130 vs 690 18 vs 18
Frame-budget chain at the logic limit, 1 / 4 / 150 links (HTML and Vue) 37 / 59 / RecursionError 37 / 37 / 37
Shallow-template chain of 150, HTML / Vue RecursionError 37 / 148
Chain forwarded through {{ content }} (unchanged) about 11 per link about 11 per link

With Vue, a chain grows about 2 frames per link until the walk that collects the browser data reaches its fixed limit of 128 frames. The reviewer confirmed that chains of 1,990 links render, and that 2,100 links stop with the max_component_depth error.

Tests

  • test_slot_forwarding_chains.py (new, 132 tests): chains of 1, 3 and 21 links in HTML and Vue. It covers on_slot_rendered arguments and replacements, slot data, fallbacks, provides, nested and empty fills, an expression link, a Python fill at the end, and each error kind with its path and position. The snapshots were recorded on e1c370f9e, before the change, and pass on both render paths after it. Every error test also checks that no slot generator is left paused and that both context variables are reset.
  • The frame-budget test now renders 150-link chains: at most 20 frames over a one-link chain, plus 128 with Vue. _measure reports a RecursionError as a result instead of crashing the worker. The new fixtures add about 45 seconds to each render path in the qualification run.
  • test_render_depth_frames.py now compares chains of 8 and 64 links.
  • Focused suites (61 files) pass on both render paths. The 12 local failures fail the same way on main, because the local citry_core build is older than recent Rust merges, so CI is the full proof here. ruff is clean, and mypy is clean with and without --platform linux.
  • An independent reviewer found no behavior differences in 18 extra cases. Its findings and a separate prose pass are folded in.

Speed gate (2%)

Run on a quiet machine with the other lanes paused. The 1-minute load average stayed between 2.0 and 3.5.

benchmarks/slot_renders.py (new) renders 300 filled, fallback, or passed-on slots per page, alternating base and head in fresh processes:

Scenario min base -> head median base -> head
filled, native on 20.339 -> 20.332 ms (-0.03%) 20.895 -> 20.353 ms (-2.59%)
filled, native off 20.696 -> 20.275 ms (-2.03%) 20.959 -> 20.649 ms (-1.48%)
fallback, native on 18.019 -> 17.826 ms (-1.07%) 18.425 -> 18.730 ms (+1.66%)
fallback, native off 18.082 -> 17.933 ms (-0.82%) 18.329 -> 18.123 ms (-1.12%)

benchmarks/compare.py --size lg, citry rows only, 7 rounds per cell, with head and base interleaved twice. Subsequent render, medians: native on, head 66.8 / 67.6 ms vs base 69.3 / 69.2 ms; native off, head 67.6 / 68.3 ms vs base 69.8 / 67.4 ms. Startup, import, first render and the citry-const cells are all within 1.5% in both directions.

🤖 Generated with Claude Code

A component that passes its slot content on with
`<c-fill><c-slot /></c-fill>` used to start a new run of the body
renderer for every component in the chain, about 10 Python frames per
link, so a chain of about 100 raised RecursionError. The slot now hands a
plain template fill to the body renderer that is already running, the
way it already hands over its own fallback, through one shared generator
that holds the same scopes, runs the same checks and wraps the result
the same way as the Slot call it replaces. Any other fill (a Python
function, a Slot subclass, a fill from another session, or any fill while
code has replaced Slot.__call__ or the template content's methods) still
goes through the Slot call.

A chain now takes 18 frames at 8 or 64 links without Vue (130 and 690
before); with Vue it grows 2 frames per link up to the fixed cap of the
browser-data walk (148 frames at 150 links, which used to raise).

Parity snapshots for chains of 1, 3 and 21 links (HTML and Vue, slot
hook arguments and replacements, slot data, fallbacks, provides, nested
and empty fills, and each error kind) were recorded on the code before
the change and pass on both render paths after it. The frame-budget test
renders 150-link chains under its budget, and the depth test compares
chains of 8 and 64 links. benchmarks/slot_renders.py compares two
checkouts on pages of 300 filled, fallback, or passed-on slots.

Part of #299.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit da1c9cf into main Oct 28, 2026
9 of 25 checks passed
@JuroOravec
JuroOravec deleted the fix/render-forwarded-fills-in-the-running-loop branch October 28, 2026 20:49
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.

1 participant