Skip to content

fix: keep emptied children empty after page.update(col, controls: [...]) - #113

Merged
AdamMusa merged 13 commits into
mainfrom
fix/stale-controls-after-update
Nov 21, 2026
Merged

AdamMusa merged 13 commits into
mainfrom
fix/stale-controls-after-update

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Fixes #105

What changed

Page#update(control, controls: [...]) (and the children: alias) copied the list into control.children and also kept the app's Array in control.props["controls"]. Control#to_patch writes props first and replaces "controls" from children only unless children.empty?. The page's tree walks also read that props copy. So a control the app removed from children afterwards was still treated as mounted:

  • once the app emptied children, the old list came back in every later full view patch (a title, appbar or route change, or page.go) and in its parent's patch, for example when a sibling was added to the parent
  • whether the app removed all of the controls or only some, a removed control still got its own patch_control messages, page.get_control still found it, a client event for it still ran its handler, and a Form still validated it

In packages/ruflet_core/lib/ruflet_ui/ruflet/page.rb, Page#update now deletes props["controls"] after copying the list into children, whenever the list holds at least one Control. children is then the only store, as it already is for DSL-built containers: the *_compatibility_test files assert refute ...props.key?("controls").

A list with no Control in it (nil, [] or raw maps) has nothing children can hold, so it stays in props as the app's own Array, exactly as before. The patch sent by the targeted page.update itself is unchanged.

No app code changes are needed, and no template, engine or CLI changes are involved.

How verified

Final head f742b63, with main 84e5e0c merged in (the PR's diff against main is unchanged).

Regression tests in packages/ruflet_core/test/page_update_serialization_test.rb (24 runs, 10 of them new). Run against main's lib, the file gives 8 failures: every new test except the two no-Control ones.

  • the Emptied children come back after page.update(col, controls: [...]): later full or parent patches re-send the old list #105 cases: a full patch after children.clear, a parent patch after children.replace([]) via children:, a removed control that is no longer patched, and a mixed list (a Control plus a raw map), with the Control first and with the raw map first
  • test_control_removed_after_targeted_update_is_no_longer_mounted: only some controls removed; the bare update still sends the remaining list, and the removed ones are not patched, not found by get_control and not sent their events (Behavior change 1)
  • test_field_removed_after_targeted_update_leaves_the_form (Behavior change 1)
  • test_bare_update_after_targeted_update_with_own_children_sends_the_list_once (Behavior change 2)
  • test_targeted_update_keeps_its_own_copy_of_the_passed_list (Behavior change 4, for controls: and children:)
  • two tests showing that a list with no Control is serialized and tracked as before

I changed the fix line in a copy of the tree to check that the tests catch it:

Change to the fix line Tests that fail
line removed (main's code) 8: every new test except the two no-Control tests
delete even when the list has no Control 2: the two no-Control tests
props["controls"] = children instead of delete 4
props["controls"] = [] instead of delete 3
delete only when every item is a Control (any? && all?) 1: the mixed-list test
delete only when the first item is a Control 1: the mixed-list test (raw map first)
delete whenever the list is non-empty 1: a no-Control test

The file also passes with 5 seeds on Ruby 3.4.5 and 3 seeds on Ruby 4.0.5.

Existing suites on the final head, one process per file, Ruby 4.0.5:

Suite Files Runs Failures, errors
packages/ruflet_core 205 2091 0, 0 (1 skip: test_engine_service_types_are_current_with_the_engine, which needs an engine checkout)
packages/ruflet_server 15 64 0, 0
packages/ruflet 22 719 0, 0
packages/ruflet_rails (bundle exec, exported tree) 19 306 0, 0 (2 skips in main's rails_executor_test.rb: Active Record or sqlite3 is not installed here)
packages/ruflet_record 14 95 0, 0

H1 goldens: cd packages/ruflet && ruby test/compat/compat.rb --jobs 4 checked 314 goldens with no difference (exit 0). ruby -Ilib -Itest test/compat_goldens_test.rb: 322 runs, 0 failures.

Probes on main 27e2ffa, the published ruflet_core 0.0.23 and this branch:

Probe main and 0.0.23 this branch
full view patch after children.clear + title change ["A", "B"] []
parent patch after children.clear + appended sibling ["milk", "eggs"] []
children.replace([]) + title change ["r1", "r2"] []
delete one by one + appbar change ["Bar", "a", "b"] ["Bar"]
page.go("/other") after clear ["e1"] []
mixed list, children.clear + title change ["milk", "raw"] []
some controls removed, patches for the column (bare update; full view patch) the remaining list: ["keep"]; ["k1"] the same: only this wire output is unchanged
some or all controls removed: value change of a removed control patch sent not sent
some or all controls removed: page.get_control("gone_id") the removed control nil
some or all controls removed: click sent to a removed button's wire id handler runs handler does not run
some or all fields removed from a Form (main only) fields 2, validate false, error patch sent to the removed field fields 1, validate true, nothing sent to it
DSL-built column, same removals (baseline) ["keep"], not sent, nil, handler does not run, fields 1 the same

Embedded VM: I built an arm64 libruflet_vm.a from 4f3bb43, before the last six main merges. They touch the CLI, the icon-prop encoding in page.update, event data, ruflet_record and ruflet_rails, not the controls path (#98, #109, #103, #90, #111, #102) (tools/build_apple_vm_artifacts.sh macos --output, narrowed to arm64 in a scratch copy because this Mac has no Rosetta, against a fresh clone of mruby 449627d). Its framework source contains the fix line. A 20-check probe of the cases above, including the raw-first mixed list, the partial removal and the form, gives the same 20 results in that VM as on CRuby. Harness tests on that VM: client_state_readers, icon_deferral, scoped_helper, ruflet_gem, ruflet_record_gem and run_in_process_test.sh pass. compat_test stops at line 67 (SystemExit is undefined) and regexp_test stops at line 132 (partition with a Regexp). Both are standard-library checks that do not touch the page.

Behavior changes

Each item is a bug fix (D6). No app code has to change.

  1. Removed controls stop counting as mounted. After page.update(col, controls: [...]), a control that the app later removes from col.children is no longer part of the page. This holds whether the app removes all of the controls or only some. On main and 0.0.23 the props copy kept it in the page's tree walks, so:

    • (a) a bare page.update still sent patch_control messages for changes to it;
    • (b) page.get_control(id) returned it instead of nil;
    • (c) a client event sent to its wire id still ran its handler;
    • (d) Form#fields still listed it, so Form#validate, values, errors and autovalidation used it. A removed, empty required field made validate return false and got an error patch. Form exists on main only, not in 0.0.23.

    When children was emptied, later full and parent patches also sent the removed controls again (the issue itself).

    • Why this is a bug fix: the client no longer shows these controls. A DSL-built container, column(controls: [...]), already drops a removed control in all four ways on main and 0.0.23 (last probe row).
    • What stays the same: the patch for the container itself. Removing only some controls sends the remaining list, as before.
  2. Duplicate op removed. After page.update(list, controls: list.children), props["controls"] was the same Array as children. A later bare page.update that changed the children then sent two identical [0, 0, "controls", [...]] ops in one patch. It now sends one.

  3. Key order only. In a full serialization of a control that got page.update(col, controls: [controls...]), the "controls" key now comes last in the map, as it already does for DSL-built containers. Before, it sat where it was first inserted into props. For example, ["_c", "_i", "_internals", "spacing", "controls"] instead of [..., "controls", "spacing"]. The content is the same, and the renderer reads keys by name.

  4. Later changes to the passed Array are not sent. page.update(col, controls: items) copies the Controls into col.children, which is what column(controls: items) has always done. If the app keeps items and changes it afterwards, a bare page.update sends nothing. Changing col.children instead is sent, as before. The same applies to children: items.

    • Example: items << text("second") then page.update. Main and 0.0.23 sent ["first", "second"], and this branch sends nothing. With items.clear, main sent [], and this branch sends nothing.
    • Why this is a bug fix: on main that change reached the client only from the props copy, while children kept the old list. So the next full or parent patch undid it. After items << second, a title change sent ["first"] on main and 0.0.23, and the appended item disappeared. After items.clear, it sent ["a", "b"], and the cleared items came back. DSL-built containers never tracked the passed Array: column(controls: items); items << x; page.update sends nothing on main, on 0.0.23 and on this branch.
    • Who it affects: the docs and the in-repo callers always pass a new Array, so none of them hit this. That covers controls_and_layout.md, control_progress_ring.md and the ruflet_rails shell and html_app.
  5. col.props["controls"] reads back nil after such an update. Before, it returned the list. Read col.children instead. The docs only read props["value"].

Lists with no Control in them are unchanged. One consequence: items = []; page.update(col, controls: items); items << text("e1"); page.update still sends ["e1"], as on main, because that Array stays in props. A list that held a Control does not do this (item 4).

Page#update copied a "controls" patch into control.children and also
left it in control.props. Control#to_patch only overrides "controls"
from a non-empty children list, so after the app emptied children the
stale props copy was sent again in every later full or parent patch,
and the removed controls stayed in the page's mounted state.

children is now the only store once the list holds a Control, as it is
for DSL-built containers. Lists with no Control in them (nil, [], raw
maps) stay in props as before.

Fixes #105
- A mixed list (a Control plus a raw map) also leaves no stale copy in
  props once children is emptied.
- The passed list is copied into children, as for DSL-built containers:
  later changes to the app's own Array are not sent, changes to
  col.children are (controls: and children:).
- A list with no Control in it stays the app's own Array in props, so a
  later change to it is still sent, as before the fix.
@AdamMusa
AdamMusa merged commit 4ca7634 into main Nov 21, 2026
10 checks passed
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.

Emptied children come back after page.update(col, controls: [...]): later full or parent patches re-send the old list

1 participant