Skip to content

page.update encodes icon props differently from construction: show_*_icon booleans raise ArgumentError, leading/trailing icon names are sent as Strings the renderer drops #108

Closed

Description

@AdamMusa

page.update(control, **props) is the documented way to change a prop. For icon-related props it encodes values differently from construction, so two things break:

  • A boolean show_*_icon prop raises ArgumentError, which aborts the handler.
  • An icon name in leading: or trailing: is sent as a raw String. The renderer drops a String, so the icon disappears on the client.

Reproduced on main (a309af5) and on the published ruflet_core 0.0.23.

Repro

require "ruflet"

sent = []
page = Ruflet::Page.new(session_id: "s1", client_details: { "route" => "/" },
                        sender: ->(_action, payload) { sent << payload })

snack_bar = Ruflet.snack_bar(content: Ruflet.text("Saved"), show_close_icon: true) # construction accepts the boolean
page.show_snack_bar(snack_bar)
page.update(snack_bar, show_close_icon: false)
# => ArgumentError: page show_close_icon must use an icon name string, not false

tile = Ruflet.list_tile(title: Ruflet.text("Row"), leading: "home")
page.add(tile)
tile.props["leading"]          # => 69217 (a codepoint, from construction)
page.update(tile, leading: "info")
sent.last["patch"]             # => [[0], [0, 0, "leading", "info"]]  (raw String)

The same ArgumentError comes from page.update(segmented_button, show_selected_icon: false), page.update(expansion_tile, show_trailing_icon: false) and page.update(data_cell, show_edit_icon: true). The same raw-String leading/trailing comes from expansion_tile, cupertino_list_tile and banner.

Expected

page.update encodes these props the way construction does:

  • show_close_icon, show_edit_icon, show_selected_icon and show_trailing_icon are sent as the booleans they are. The engine reads each one with getBool.
  • An icon name in leading:/trailing: is sent as its codepoint, as Ruflet.list_tile(leading: "info") sends it.

Actual

  • Toggling a show_*_icon flag from a handler raises.
  • Changing a leading/trailing icon by name makes it vanish. buildIconOrWidget (engine extensions/control.dart, also vendored in the template) draws a Control or an int codepoint and returns null for a String. That holds for list_tile, cupertino_list_tile, expansion_tile and banner.

Where

  • packages/ruflet_core/lib/ruflet_ui/ruflet/page.rb, Page#icon_prop_key?: key == "icon" || key.end_with?("_icon"). It treats every show_*_icon key as an icon name and does not cover leading/trailing. Page#normalize_value then raises for a boolean.
  • packages/ruflet_core/lib/ruflet_ui/ruflet/control.rb, Control#icon_prop_key?, has the rule construction uses: return false if key.start_with?("show_"), plus leading and trailing. Commit bd12e93 added those cases to Control but not to Page.

Workaround

Set the prop directly and call a bare page.update, for example snack_bar.props["show_close_icon"] = false; page.update.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions