Repository navigation
fix: keep emptied children empty after page.update(col, controls: [...]) - #113
Merged
Merged
Conversation
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.
- The mixed-list case now covers a raw map first as well as a Control first. - A control removed from children after page.update(col, controls: ...) is no longer patched, found by page.get_control or sent its events, also when other controls stay in the list. - A field removed that way is no longer one of the form's fields, so Form#validate skips it.
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.
Fixes #105
What changed
Page#update(control, controls: [...])(and thechildren:alias) copied the list intocontrol.childrenand also kept the app's Array incontrol.props["controls"].Control#to_patchwrites props first and replaces"controls"from children onlyunless children.empty?. The page's tree walks also read that props copy. So a control the app removed fromchildrenafterwards was still treated as mounted:children, the old list came back in every later full view patch (a title, appbar or route change, orpage.go) and in its parent's patch, for example when a sibling was added to the parentpatch_controlmessages,page.get_controlstill found it, a client event for it still ran its handler, and aFormstill validated itIn
packages/ruflet_core/lib/ruflet_ui/ruflet/page.rb,Page#updatenow deletesprops["controls"]after copying the list intochildren, whenever the list holds at least one Control.childrenis then the only store, as it already is for DSL-built containers: the*_compatibility_testfiles assertrefute ...props.key?("controls").A list with no Control in it (
nil,[]or raw maps) has nothingchildrencan hold, so it stays in props as the app's own Array, exactly as before. The patch sent by the targetedpage.updateitself 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'slib, the file gives 8 failures: every new test except the two no-Control ones.children.clear, a parent patch afterchildren.replace([])viachildren:, 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 firsttest_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 byget_controland 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, forcontrols:andchildren:)I changed the fix line in a copy of the tree to check that the tests catch it:
props["controls"] = childreninstead of deleteprops["controls"] = []instead of deleteany? && all?)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:
packages/ruflet_coretest_engine_service_types_are_current_with_the_engine, which needs an engine checkout)packages/ruflet_serverpackages/rufletpackages/ruflet_rails(bundle exec, exported tree)rails_executor_test.rb: Active Record or sqlite3 is not installed here)packages/ruflet_recordH1 goldens:
cd packages/ruflet && ruby test/compat/compat.rb --jobs 4checked 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:
children.clear+ title change["A", "B"][]children.clear+ appended sibling["milk", "eggs"][]children.replace([])+ title change["r1", "r2"][]["Bar", "a", "b"]["Bar"]page.go("/other")after clear["e1"][]children.clear+ title change["milk", "raw"][]["keep"];["k1"]page.get_control("gone_id")nilForm(main only)fields2,validatefalse, error patch sent to the removed fieldfields1,validatetrue, nothing sent to it["keep"], not sent,nil, handler does not run,fields1Embedded VM: I built an arm64
libruflet_vm.afrom 4f3bb43, before the last six main merges. They touch the CLI, the icon-prop encoding inpage.update, event data,ruflet_recordandruflet_rails, not thecontrolspath (#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_gemandrun_in_process_test.shpass.compat_teststops at line 67 (SystemExitis undefined) andregexp_teststops at line 132 (partitionwith 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.
Removed controls stop counting as mounted. After
page.update(col, controls: [...]), a control that the app later removes fromcol.childrenis 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:page.updatestill sentpatch_controlmessages for changes to it;page.get_control(id)returned it instead ofnil;Form#fieldsstill listed it, soForm#validate,values,errorsand autovalidation used it. A removed, empty required field madevalidatereturnfalseand got an error patch.Formexists on main only, not in 0.0.23.When
childrenwas emptied, later full and parent patches also sent the removed controls again (the issue itself).column(controls: [...]), already drops a removed control in all four ways on main and 0.0.23 (last probe row).Duplicate op removed. After
page.update(list, controls: list.children),props["controls"]was the same Array aschildren. A later barepage.updatethat changed the children then sent two identical[0, 0, "controls", [...]]ops in one patch. It now sends one.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.Later changes to the passed Array are not sent.
page.update(col, controls: items)copies the Controls intocol.children, which is whatcolumn(controls: items)has always done. If the app keepsitemsand changes it afterwards, a barepage.updatesends nothing. Changingcol.childreninstead is sent, as before. The same applies tochildren: items.items << text("second")thenpage.update. Main and 0.0.23 sent["first", "second"], and this branch sends nothing. Withitems.clear, main sent[], and this branch sends nothing.childrenkept the old list. So the next full or parent patch undid it. Afteritems << second, a title change sent["first"]on main and 0.0.23, and the appended item disappeared. Afteritems.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.updatesends nothing on main, on 0.0.23 and on this branch.controls_and_layout.md,control_progress_ring.mdand theruflet_railsshell and html_app.col.props["controls"]reads backnilafter such an update. Before, it returned the list. Readcol.childreninstead. The docs only readprops["value"].Lists with no Control in them are unchanged. One consequence:
items = []; page.update(col, controls: items); items << text("e1"); page.updatestill sends["e1"], as on main, because that Array stays in props. A list that held a Control does not do this (item 4).