Skip to content

fix: reclaim DSL prop controls only from child-control slots - #64

Merged
AdamMusa merged 1 commit into
mainfrom
fix/dsl-reclaim-control-slots
Nov 6, 2026
Merged

AdamMusa merged 1 commit into
mainfrom
fix/dsl-reclaim-control-slots

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Problem

The v0.0.23 → main compatibility audit found a regression from #48 (PropControls.reclaim) on an undocumented but plausible path.

PropControls.each_control walked every Hash and Array prop, including data:. A control the app only references was taken out of the block that built it:

page.add(column { label = text("0"); button(content: text("+"), data: { target: label }) })

The same finding also covered reuse after a block has returned. App/Kernel blocks kept owning their children, so passing a block child to a later prop silently mutated a parent that was already built, even one already mounted:

col = column { saved = text("shared"); text("other") }
page.add(col)
page.add(container(content: saved))   # main: col.children becomes ["other"], with no page call

Ruflet.column { ... } (WidgetBuilder) blocks did not have this problem: they copy their list into the node. So the two block forms also disagreed.

Audit evidence: compat/risk/probes/p01h_reclaim_edges.rb. Baseline col_children_after_reuse is ["shared","other"] and main is ["other"]. The baseline tree keeps text(0) in the column and main drops it.

Why it matters for existing apps

data: is the application's own payload. Storing a control reference in it (a target to update, a label to toggle) is a normal pattern, and it worked in v0.0.23. After #48 the control silently disappears from the layout with no error. The reuse case changes an already-mounted parent behind the app's back, and the next full patch (reconnect, register_page_patch) then drops the control on the client.

Fix

packages/ruflet_core/lib/ruflet_ui/ruflet/ui/prop_controls.rb

  • Reclaim looks only at child-control slots. A slot is a prop whose value is a control or a list of controls. That is the wire shape of every child prop: content:, title:, leading:, appbar:, actions:, controls:/children:, tabs:, and extension lists such as markers:, rods: and layers:.
    • A Hash value (style, theme, border, ...) is a value object, not a child slot, so it is not walked.
    • data: (OPAQUE_PROP_KEYS) is never a slot, whatever its shape.
    • On deriving slots from the schema: Ruby's schema (KEYWORDS) has names only, no types, so it cannot say which keys hold controls. A hand list of names would need about 70 core names plus every extension's own. I instrumented reclaim over the whole test suite and all 183 doc examples: every reclaim it took was a top-level control or a direct array element, from more than 30 different keys. The only Hash-nested reclaims were the two fix: keep DSL prop controls out of block children #48 tests that used data:. Recognising the protocol shape covers all of these, with no list to keep in sync.
  • A finished block's children are final. PropControls.release(list) clears implicit ownership when a block returns. App blocks call it in ensure (dsl.rb), and WidgetBuilder calls it on its nested list. That is what WidgetBuilder already did in effect, so both block forms now agree. Reclaim also skips a control that is already mounted (runtime_page set), so a mounted root is never taken out of the app's roots. Reclaim inside an open block is unchanged, so every fix: keep DSL prop controls out of block children #48 case still works: column { t = text("x"); row { container(content: t) } }.

No change to how apps are written. The cases #48 fixed (content/title/actions/children duplicated as siblings) stay fixed.

Tests

  • New packages/ruflet_core/test/dsl_reclaim_control_slots_test.rb (12 tests): data: references kept in Ruflet.column, bare Kernel, DSL.app blocks/roots and page.mount; data: holding a control or a list; the mounted wire carries + once; a unit test of the slot rule; reuse after a block returned (Kernel, mounted and unmounted); App and WidgetBuilder agreeing after an inner block returned; a mounted app root staying a root.
    • On main: 11 of 12 fail. The 12th, WidgetBuilder mounted reuse, already passes on main and guards consistency.
  • dsl_block_prop_children_test.rb: two fix: keep DSL prop controls out of block children #48 tests asserted data: reclaim. test_builder_block_does_not_duplicate_controls_in_a_deeply_nested_hash (a data: hash) now asserts the referenced control stays, and is renamed ..._keeps_a_control_referenced_from_a_nested_data_hash. The ancestor-reclaim test drops its incidental data: { label: top }, and its two-level assertions are unchanged.
  • All suites pass: ruflet_core, ruflet_server, ruflet (CLI) and ruflet_rails, each run per file.
  • I ran the new PropControls under the embedded mruby VM (tools/embedded_vm_harness/build/embedded_mruby). It loads and behaves the same.

Doc-example harness

I ran all 183 documented examples on this branch and compared them with the v0.0.23 baseline outputs, ignoring tree_probe: 0 differ (180 identical, 3 skipped, as on main). No example changed behaviour.

The audit probe p01h_reclaim_edges now matches baseline. col_children_after_reuse is ["shared","other"] and text(0) stays in the column. The one remaining difference is the duplicated text("+") sibling that #48 removed on purpose.

ruflet#48 made every builder take a control back from its block when the
control was passed as a prop, but it walked every Hash and Array prop,
data: included. A control the app only references, such as
`column { t = text("0"); button(content: text("+"), data: { target: t }) }`,
was removed from its block, which v0.0.23 never did.

Reclaim now only looks at child-control slots: a prop whose value is a
control or a list of controls, which is the wire shape of every child prop
(content:, title:, actions:, controls:/children:, tabs:, markers:, ...).
Hash values are value objects and data: is opaque, so a control referenced
from them stays where its block put it.

App blocks also kept owning their children after they returned, so reusing
a block child in a later prop (often after the parent was mounted) silently
took it out of that parent. A block now releases its children when it
returns, as WidgetBuilder blocks effectively did, and a mounted control is
never taken out of the app's roots.
@AdamMusa
AdamMusa merged commit 2683c41 into main Nov 6, 2026
13 of 14 checks passed
AdamMusa pushed a commit that referenced this pull request Nov 7, 2026
Brings in #64 (reclaim only from child-control slots), #65 and #66
(Dropdown change event name and spellings) and #68 (inline date pickers
in DSL blocks).

Conflicts:
- Page.presented_control?: #68 and this branch both exempt inline date
  pickers; kept this branch's inline_overlay? rule (any presented
  overlay built with inline: true), which #68's new tests also pass.
- PropControls.reclaim: kept #64's child-slot walk and mounted-control
  rule together with this branch's last-first order; the comment covers
  both. Page#claim_prop_control now passes its value as a one-slot props
  hash, since reclaim reads props.
- Dropdown contract and its test file: both sides' additions kept.

ruflet_core 186/186 files (1039 runs), ruflet_rails 16/16, ruflet_record
5/5; ruflet_server and ruflet only the two environment-specific failures
that also fail on main here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MqfxcsDiEUZngybe9L72JQ
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