Skip to content

fix: deliver dropdown on_change handlers the "change" event name - #65

Merged
AdamMusa merged 1 commit into
mainfrom
fix/dropdown-on-change-event-name
Nov 6, 2026
Merged

AdamMusa merged 1 commit into
mainfrom
fix/dropdown-on-change-event-name

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Problem

Compatibility audit (v0.0.23 c1c366c9 vs main 61837818), dropdown section:

#28 maps the Material 2 dropdown event onto the canonical Dropdown event: dropdown_m2(on_change:), dropdownm2(on_change:), dropdown(on_change:) and on(:change) now store the handler under "select", and the wire carries on_select: true. That part is right, because the Dropdown renderers only fire select (engine material_dropdown.dart:315, cupertino_input_controls.dart). Before #28 these handlers never ran on a real client.

But the handler is called with the client's event unchanged, so event.name is "select". Legacy handler code that checks event.name == "change" no longer matches. Audit probe risk/probes/p04_dropdown.rb, calls recorded per handler as [handler, event.name]:

tree handlers registered via on_change
v0.0.23 ["m2.on_change","change"] (only for a synthetic change; the renderer's select never reached it)
main ["m2.on_change","change"], ["m2.on_change","select"], ["m2b.on_change","select"], ["dd.on_change","select"]
this PR every on_change call sees "change"

Why it matters for existing apps

The owner's rule is that this work must not change how developers write Ruflet apps. dropdown_m2 and on_change are undocumented, but they are plausible in apps written against the Material 2 API. Handlers that branch on event.name (a shared handler for several controls, or a case event.name) would run but take the wrong branch.

Fix

In PlatformControlContracts::Components::DropdownControl, a handler registered under the Material 2 spelling is wrapped when it is stored. That covers on_change: in the constructor or in merge_props (through preprocess_props), plus on(:change), on(:on_change), on("change") and attach_handler(:change / :on_change). The wrapper calls it with the same event renamed to "change":

  • It is still stored under "select", and the wire still sends on_select: true. Nothing changes on the protocol side.
  • Only the name differs. Target, control, page, raw_data, data, typed_data and value are the ones an on_select handler gets. The new Ruflet::Event#with_name(name) makes the copy with dup plus instance_variable_set, which is mruby-safe and already used in page.rb.
  • Handlers registered with on_select: / on(:select) still see "select". Replacing an on_change handler with on(:select) delivers "select".
  • The wrapper travels with the handler, so the Rails ControlDiff handler copy keeps working.
  • normalized_event_name now reads the new MATERIAL2_EVENTS table instead of a hard-coded "change".

Tests

packages/ruflet_core/test/dropdown_compatibility_test.rb, written first. On main's library code, 4 failures (14 runs, 118 assertions, 4 failures):

  • test_dropdown_m2_on_change_fires_on_the_canonical_select_event: now expects [["change","blue"]]. It used to pin "select".
  • test_dropdown_m2_change_handler_attached_later_fires_on_select: on(:change) sees "change".
  • test_material2_change_handlers_see_change_while_on_select_handlers_see_select: 12 registration paths across dropdown, dropdown_m2 and dropdownm2 (constructor, on and attach_handler, each spelling).
  • test_material2_change_handler_gets_the_same_event_data_as_an_on_select_handler: the same raw_data, data, value, typed_data class, selection, control, page and target as an on_select handler.
  • Regression guards that already pass on main: a client change is still delivered as "change", and replacing the handler with on(:select) delivers "select".

With the fix, all suites pass: packages/ruflet_core, ruflet_server, ruflet and ruflet_rails, each file run on its own.

The new DropdownControl and Event code was also run verbatim on the embedded VM (tools/embedded_vm_harness/build/embedded_mruby --preload), on top of a copy of Control's handler plumbing. Its output matched CRuby exactly.

Doc harness

All 183 documented examples were run with the compat harness (run.rb <worktree> <id>) and compared to the v0.0.23 baseline, ignoring tree_probe. The result is {"same" => 183}. No documented example changes, and none was meant to: the documented dropdown API is on_select.

This PR and #66 (warn instead of raising on both spellings) both edit DropdownControl#preprocess_props, in separate hunks. I test-merged the two on main: the merge is clean, the combined dropdown tests pass (16 runs), and the doc harness is still {"same" => 183}.

Since #28 a dropdown_m2 / dropdown on_change handler (or on(:change))
is stored under the canonical Dropdown "select" event, so it finally
runs when the renderer fires "select". But it is called with that
event as is, so event.name is "select" and legacy handler code that
checks event.name == "change" stops matching.

Wrap handlers registered under the Material 2 spelling (on_change:,
on(:change), on(:on_change), attach_handler(:change)) so they are
called with the same event renamed to "change". Only the name differs:
target, control, page, raw_data, data, typed_data and value are the
ones an on_select handler gets (new Event#with_name copies the event).
Handlers registered with on_select still see "select", and the wire
still carries on_select: true.
@AdamMusa
AdamMusa merged commit a0bd105 into main Nov 6, 2026
12 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