Skip to content

fix: warn instead of raising when a dropdown gets both key spellings - #66

Merged
AdamMusa merged 1 commit into
mainfrom
fix/dropdown-both-spellings-warn
Nov 6, 2026
Merged

AdamMusa merged 1 commit into
mainfrom
fix/dropdown-both-spellings-warn

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 renames the Material 2 dropdown keys onto the Dropdown contract: on_change becomes on_select, max_menu_height becomes menu_height, prefix_icon becomes leading_icon and select_icon becomes trailing_icon. When a call passes a Material 2 key together with its Dropdown key, it now raises:

ArgumentError: dropdown accepts :on_select or its Material 2 spelling :on_change, not both

Audit evidence (surface/behavior_probe.rb P2/P3b, risk/probes/p04_dropdown.rb):

  • v0.0.23: dropdown(on_select: a, on_change: b) loaded and sent {"on_change"=>true,"on_select"=>true}.
  • main: raises ArgumentError, and so does dropdown(prefix_icon:, leading_icon:).
  • this PR: loads, prints one warning per pair, and keeps the Dropdown key.

Why it matters for existing apps

The owner's rule is that this work must not change how developers write Ruflet apps. An app that passed both spellings (common when porting Material 2 code by adding the new key without deleting the old one) loaded on v0.0.23. On main it raises while it builds the view, so the whole page fails, not just the dropdown.

Fix

In DropdownControl#preprocess_props, when both spellings of a pair are present the code now calls Kernel.warn and drops the Material 2 value. Kernel.warn is the mruby-safe form already used in page.rb and control.rb. The warning reads:

dropdown: both :on_select and its Material 2 spelling :on_change were given; using :on_select and ignoring :on_change
  • The Dropdown key wins, matching what the renderers read. For events, the on_select handler is the one that runs, both for the renderer's select and for a change.
  • A lone key of either spelling is unchanged and does not warn.
  • The ArgumentError text is gone; nothing else in the tree or the docs referred to it.

Tests

packages/ruflet_core/test/dropdown_compatibility_test.rb, written first. On main's library code, 2 errors (ArgumentError ... not both):

  • test_dropdown_m2_warns_and_keeps_the_dropdown_key_when_both_spellings_are_given: exactly one warning naming :on_select and :on_change. The wire has on_select: true and no on_change. The on_select handler runs for both select and change.
  • test_every_material2_key_given_with_its_dropdown_spelling_warns_and_the_dropdown_key_wins: all three non-event pairs on dropdown, dropdown_m2 and dropdownm2, giving three warnings with the Dropdown values kept.
  • test_a_lone_material2_key_or_dropdown_key_does_not_warn: a regression guard.

This replaces test_dropdown_m2_rejects_a_material2_key_together_with_its_dropdown_spelling, which pinned the raise. Warnings are captured with $VERBOSE = false, so the test does not depend on how the suite is invoked.

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

The new preprocess_props was also run verbatim on the embedded VM (tools/embedded_vm_harness/build/embedded_mruby --preload). Warnings, wire props and handler dispatch were identical to CRuby.

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 comparison includes stderr. The result is {"same" => 183}. No documented example passes both spellings, so none changes or starts warning.

This PR and #65 (on_change handlers see "change") both edit 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, passing a Material 2 dropdown key together with its Dropdown
spelling (on_change: with on_select:, max_menu_height: with
menu_height:, prefix_icon: with leading_icon:, select_icon: with
trailing_icon:) raises ArgumentError. That code loaded in v0.0.23, so
an app that passed both now fails to build its view.

Warn once per pair with Kernel.warn (mruby-safe, as elsewhere in
ruflet_core) and keep the Dropdown key; the Material 2 value is
dropped. A lone key of either spelling is unchanged and does not warn.
@AdamMusa
AdamMusa merged commit 2acfca4 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