Repository navigation
fix: collect Ruflet.* helpers called inside DSL blocks - #50
Merged
Merged
Conversation
Inside a DSL block every helper attaches the control it builds to the
enclosing builder. Arguments are evaluated first, so in
column { list_tile(title: text("T"), subtitle: text("S")) } both Text
controls were attached as column children before the ListTile consumed them,
and the column rendered Text, Text, ListTile. The same happened for content:,
actions: [...], children:/controls: and nested hashes, in WidgetBuilder blocks
(Ruflet.column { ... }, Page#mount, center) and in the Ruflet::DSL app used by
the bare top-level helpers. There, top-level props and page(appbar: ...) also
leaked into the app's root controls.
Both builders now record the controls they attach. After building a control
(or merging page props), they walk its prop values through Hash and Array and
take back, by identity, any control they had attached. Explicit block children,
the block-result child, and children:/controls: handling are unchanged.
Each nested WidgetBuilder only took back prop controls that it had
attached itself. A control created in an outer block and used as a prop one or
more levels deeper stayed a child of the outer block:
column { t = text("x"); row { container(content: t) } } still gave
column [Text, Row].
Builders now attach implicit children through PropControls.attach, which
records the owning list on the control (Control#dsl_owner, internal and never
serialized). PropControls.reclaim takes a prop control back from that owner,
matching by identity, whichever builder or enclosing block attached it. This
also covers a WidgetBuilder nested in a DSL app block (center { } inside
app.column { }). Explicit children are never given an owner, so they are never
taken back.
Each Ruflet.* helper built its control with a fresh WidgetBuilder, so inside
Ruflet.column { Ruflet.text("a"); Ruflet.text("b") } only the block's return
value ("b") became a child. Inside a bare column { } block, which is
evaluated by the DSL app, Ruflet.* children were dropped entirely.
Builders now push themselves onto Ruflet::UI::BuildScope around instance_eval
and pop in ensure. This covers WidgetBuilder blocks, center, Page#mount,
Ruflet::DSL.app, App#page and App#control. Ruflet's control_delegate uses the
current builder when there is one, so Ruflet.* appends exactly like the bare
helpers and gets the prop-control de-duplication from the previous fix.
Outside every block it still returns a standalone control with no side
effects.
The stack is per thread (Thread.current[]), because the server builds each
session on its own thread. The mruby Thread polyfill provides the same API.
App#control now also pops its parent stack in ensure, so a raising block no
longer leaves later top-level controls attached to the failed parent.
AdamMusa
force-pushed
the
fix/dsl-prefixed-block-children
branch
from
October 28, 2026 15:52
8c1fba5 to
92eb7cf
Compare
Every helper attached the control it built to the enclosing block, overlays
and services included. With Ruflet.* now captured as well,
column { dlg = Ruflet.alert_dialog(...); button(on_click: ->(e) { page.open(dlg) }) }
left the dialog in the column and also mounted it in the page's dialogs, with
one wire id in two places. Bare helpers already did this before, and a
top-level alert_dialog(...) became a body control that page.open mounted a
second time.
Page::PRESENTED_TYPES, keyed on wire type, is the set PropControls.attach (the
single implicit-attach point for WidgetBuilder and the DSL app) skips:
- the presented overlays: AboutDialog, AlertDialog, Banner, BottomSheet,
DatePicker, DateRangePicker, SnackBar, TimePicker. Picker, TimerPicker and
ActionSheet render inline in the engine and stay children.
- every wire type the engine registers with createService, core and extension
packages: Ruflet::UI::ServiceTypes::ENGINE_SERVICE_TYPES, generated from the
engine sources by tools/sync_engine_service_types.rb (--check verifies it).
That adds Audio, InterstitialAd and Window to the RufletServices entries.
Camera is a createWidget control, so it is not listed and stays a child.
Page#service_control_type? and the ruflet_rails HTML transformer's service tags
now use the same engine-derived set instead of their own hand lists. Explicit
controls:/children: and a block's return value still place an overlay in a
layout. Control#wire_type exposes the wire type that to_patch already
computed.
AdamMusa
force-pushed
the
fix/dsl-prefixed-block-children
branch
from
October 28, 2026 22:38
92eb7cf to
b1bf9b7
Compare
This was referenced Nov 6, 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.
Depends on #48 (
fix/dsl-block-prop-children). This branch is stacked on it, and the base ismain, so the diff includes #48's two commits until #48 merges. This PR's commits are:fix: collect Ruflet.* helpers called inside DSL blocksfix: keep overlays and services out of implicit DSL block children(lead decision after QA review, amended to un-exclude the inline pickers and derive services from the engine)Problem 1:
Ruflet.*inside blocksEach
Ruflet.*helper built its control with a freshWidgetBuilder(Ruflet'scontrol_delegateinlib/ruflet_ui.rb). Inside a block, only the block's return value was captured:Ruflet.column { Ruflet.text("a"); Ruflet.text("b") }ba, bRuflet.column { Ruflet.text("top"); Ruflet.row { ... }; Ruflet.text("bottom") }bottomtop, Row, bottomcolumn { Ruflet.text("a"); Ruflet.text("b") }(DSL app)App#controlignores block resultsa, bRuflet::DSL.app { Ruflet.text("one"); ... }Text, ...page.mount { Ruflet.text("a"); Ruflet.container(...) }Text, ContainerFix
Ruflet::UI::BuildScope(ui/build_scope.rb) haswithin(builder) { ... }andcurrent. Every builder pushes itself around itsinstance_evaland pops inensure:WidgetBuilder#controlcenter { }Page#mountRuflet::DSL.app { }App#page { }App#control { }Ruflet'scontrol_delegateis nowUI::BuildScope.current || WidgetBuilder.new. Inside a block,Ruflet.text(...)goes through the enclosing builder, exactly like a baretext(...). That includes fix: keep DSL prop controls out of block children #48's prop reclaiming. Outside every block,Ruflet.*still returns a standalone control and touches nothing else.App#controlpushed its parent on@stackbut did not pop it if the block raised. Later top-level controls then attached to the failed parent. It now pops inensure.Why the stack is per thread. The API is module level (
BuildScope.within/current), but the storage isThread.current[:ruflet_build_scope]:start_client_thread). A process-global stack would let one session'sRuflet.text(...)land in another session's open block during a thread switch.Threadis always the Fiber-backed polyfill (ruby_runtime/vm/stdlib/thread.rb, installed asmrblib/01_thread.rb), which implementsThread.current,Thread#[]andThread#[]=per logical thread. QA confirmed this in the embedded VM.Problem 2: overlays and services captured as children (lead decision)
Every helper attached what it built to the enclosing block, overlays and services included. That happened with bare helpers before this PR, and after commit 1 with
Ruflet.*too. In the QA repro:dlgstayed a column child and was mounted in the page's dialogs, so the same wire id appeared twice in the client tree.This also fixes the pre-existing bare-helper double mount. On
main:column { alert_dialog(...); ... }made the dialog a column child.dlg = alert_dialog(...)made it a page body control.page.open(dlg)then mounted it a second time.Fix
Page::PRESENTED_TYPES(page.rb, next toDIALOG_PROP_KEYSand theopen/show_dialoglogic) is the single set. It is keyed on wire type, so the Cupertino aliases are covered (for examplecupertino_alert_dialog→AlertDialog). It is the union of two parts:Page::PRESENTED_OVERLAY_TYPES: the overlays the page presents (AboutDialog,AlertDialog,Banner,BottomSheet,DatePicker,DateRangePicker,SnackBar,TimePicker).Picker,TimerPickerandActionSheetare not in it. The engine renders all three inline (LayoutControlaround a plain widget), socolumn { picker(...) }keeps working.Ruflet::UI::ServiceTypes::ENGINE_SERVICE_TYPES: every wire type the engine registers withcreateService, inpackages/rufletand everypackages/ruflet_*extension.tools/sync_engine_service_types.rb --engine <ruflet-engine>scans the engine'slib/**/*.dart, collects thecase "Wire":labels inside eachcreateServicemethod, and rewrites the marked block inui/service_types.rb.--checkexits non-zero when the block is stale.dsl_presented_controls_test.rbruns it whenRUFLET_ENGINE_ROOTis set.RufletServices::CLASS_MAP, this adds Audio, InterstitialAd and Window.createWidget, so it is not in the set and stays a child.RufletServices::CLASS_MAPentry is an engine service exceptPage::VISUAL_SERVICE_TYPES(Camera), so the Ruby service registry and the engine cannot drift apart silently.Page#service_control_type?dropped its"audio"special case and usesServiceTypes.service_name?. As a resultpage.service(:interstitial_ad)is accepted too.SERVICE_TAGSlist and uses the same predicate.<audio>and the existing tags behave as before.<interstitial-ad>,<browser-context-menu>and<window>now route to services as well, and<camera>still renders inline.PropControls.attach, the single implicit-attach point forWidgetBuilderand the DSL app, skipsPage.presented_control?(control). This applies to bare helpers andRuflet.*alike, at every block level and at the app's top level.controls:/children:and a block's explicit return value still put an overlay in a layout.Control#wire_typeexposes the wire type thatto_patchalready computed.Tests
packages/ruflet_core/test/dsl_prefixed_block_children_test.rb, 13 tests. 12 failed on the #48 base.Ruflet.*children are kept in order.Ruflet.*and bare helpers stay in order, with no duplicated prop controls.Ruflet.textoutside any block has no side effects.Page#mount,center, DSL app blocks,DSL.app { }roots, a raising App block popping the scope and@stack, and the bare Kernel DSL.packages/ruflet_core/test/dsl_presented_controls_test.rb, 15 tests. One is skipped unlessRUFLET_ENGINE_ROOTis set; it passes against engine c9b9d76.PRESENTED_TYPES= the overlays +ENGINE_SERVICE_TYPES. Audio, AudioRecorder, Flashlight, InterstitialAd, PermissionHandler, SecureStorage and Window are in it. Picker, TimerPicker, ActionSheet, Camera and layout controls are not.service_name?handles DSL names.picker,timer_pickerandaction_sheet(canonical and Cupertino aliases, bare andRuflet.*, WidgetBuilder and DSL app) stay children.control(:audio),interstitial_ad,window,widget(:flashlight).page.service(:audio | :interstitial_ad)works without a hand list.page.dialogs, and"_c":"AlertDialog"appears exactly once in the full page patch.Ruflet.*helpers: alert_dialog, cupertino_alert_dialog, snack_bar, banner, bottom_sheet, date_picker, time_picker.Page#mount.controls:and the block's return value still place overlays. Overlay props are still reclaimed.packages/ruflet_rails/test/html_dsl_test.rb: a new test checks that<interstitial-ad>,<browser-context-menu>and<audio-recorder>route to services and<picker>renders inline. The existing<audio>/<camera>test is unchanged and passes.verify_pr.sh "" <ruby-wt>withRUBY_PKGS="ruflet_core ruflet ruflet_server ruflet_rails ruflet_record", all PASS:Explorer tree check, using QA's
r48_tree_dump.rbover all 67ruflet_explorerstandalone apps plus the explorer main app, with object addresses ignored:main→ this branch: 67/68 identical.animation, which usesRandomand differs between two runs ofmain.Behaviour notes
Ruflet.*now behaves like the bare helpers: a control built there is a child unless it is consumed as a prop, or it is an overlay or service.page.open(dlg)) is no longer also laid out in the block.ruby tools/sync_engine_service_types.rb --engine <ruflet-engine>(or--checkin CI).Usage (now correct)