Skip to content

fix: deliver default page view events to page handlers - #55

Merged
AdamMusa merged 7 commits into
mainfrom
fix/default-page-view-events
Nov 2, 2026
Merged

AdamMusa merged 7 commits into
mainfrom
fix/default-page-view-events

Conversation

@AdamMusa

@AdamMusa AdamMusa commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Bug fix approved by the lead (found during Package A / A4, D-10 investigation). Ruby only; it relies on A4's Dart View refresh path (AdamMusa/ruflet-engine#46), and no engine change is needed.

Depends on #52 (A4 view-refresh, for the View on_refresh/on_end_reached keywords) and #54 (fix/page-view-methods). This branch is #52 plus a cherry-pick of #54's single commit, plus this fix. Review only the top commit, fix: deliver default page view events to page handlers.

Bugs (default page View = page.add without explicit views)

  1. A page-level handler went into @view_props, so the Proc itself was packed onto the wire (WireCodec → "#<Proc:0x…>") and no handler was registered. That applied to every page API:
    • page.on_refresh = ->(e) {} and the other on_* setters (via method_missing)
    • page.set_view_props(on_scroll: …), which is also what the top-level DSL page(on_scroll: …) uses through DSL::App#run
    • page.update(:page, on_scroll: …)
  2. page.on(:end_reached) { } registered the handler but never set on_end_reached: true, so the client never sent the event.
  3. The client fires View events with target = the implicit View id (20). That View is not a registered control, so dispatch_event silently dropped the event.
  4. Nothing could send end_refresh to that View.

Fix (page.rb, about 20 lines of code)

  • One funnel for all entry points. The on_* setters, set_view_props, the DSL page(...) props and update(:page, …) all end in assign_split_prop. A callable (or nil) on_* value there now goes through assign_page_handler:
    • it registers the handler in @page_event_handlers and sends only on_x: true;
    • the flag goes on the implicit View for View events (the on_* in ViewControl::KEYWORDS: refresh, scroll, end_reached, confirm_pop, size_change, animation_end) and on the Page otherwise (e.g. on_resize);
    • nil removes both. Non-callable values keep the old prop behavior.
  • page.on(:x) { } also sets the on_x: true flag on the implicit View for View events. Page events such as route_change keep their behavior: no flag.
  • Routing. dispatch_event sends events that target the implicit View (only when there are no explicit views) to the page handlers.
  • Acknowledgement. That routing uses the same ensure as D-2, invoking end_refresh on the implicit View via fix: route page scroll and drawer methods to the page View #54's :root_view target.
  • Explicit views, page-target events (id 1) and plain page props are unchanged.

Usage

page.add(list_of_cards)
page.on_refresh = ->(_e) { reload!; page.update }      # or page.on(:refresh) { ... }
page.on(:end_reached) { load_more!; page.update }
# DSL: page(on_scroll: ->(e) { track(e) }) { ... }

Tests

ruflet_server/test/page_handler_wire_test.rb (6 runs) does a real WireCodec.pack/unpack round trip of every message, for each entry point:

  • page.on_scroll =
  • page.set_view_props(on_scroll:)
  • the DSL page(on_scroll:) startup path (DSL::App#page → set_view_props, as run does)
  • page.update(:page, on_scroll:)
  • page.on(:scroll) { }

Each one is followed by page.add and a later page.update(:page, …). The test checks that no #<Proc/#<Method string appears on the wire, that the decoded View has on_scroll: true, and that a scroll from the implicit View reaches the handler. Before this commit, 4 of the 5 entry points failed.

ruflet_core/test/page_default_view_events_test.rb (10 runs, 41 assertions):

  • No Proc or Method in any payload. The flags are on the View for refresh, scroll and end_reached, and on the Page for resize.
  • page.on(:end_reached) and page.on(:on_refresh) set the View flags, and the event reaches the handler.
  • page.on(:route_change) and page.on(:resize) set no flags, and route_change still dispatches.
  • set_view_props and update(:page) register handlers.
  • A scroll from the implicit View reaches page.on_scroll.
  • A refresh runs the handler, its patch goes first, and the last message is end_refresh on the View id.
  • A raising handler is still acknowledged.
  • = nil clears the handler.
  • An explicit view's events still go to the view control.

verify_pr.sh "" <this tree> with RUBY_PKGS="ruflet_core ruflet ruflet_server ruflet_rails":

  • ruflet_core 152/152 files, 661 runs
  • ruflet 13/13 (160)
  • ruflet_server 12/12 (46)
  • ruflet_rails 15/15 (278)
  • all PASS

Wire-key audit against engine #46: NEW 0.

ListView, GridView, Column, Row, View and ReorderableListView now share a
ScrollableMethods mixin whose scroll_to invokes the renderer's existing
scroll_to method (offset, delta, scroll_key, duration, curve) on that
control instead of only on the page.
ListView, GridView and Column accept on_refresh plus refresh_color,
refresh_bgcolor, refresh_displacement, refresh_trigger_distance and
refresh_timeout. Page#dispatch_event invokes end_refresh on the control
once a refresh handler returns, also when it raises, so the native spinner
stops right after the handler's patches. ScrollableMethods gains a public
end_refresh for refreshes that finish later.
ListView, GridView, Column and Row accept on_end_reached and
end_reached_threshold. The event carries pixels, max_scroll_extent and
viewport_dimension and is mapped to GenericEvent.
ListView, GridView, Column, Row, View and ReorderableListView accept
keyboard_dismiss_behavior ("manual" or "onDrag") so dragging a form
can dismiss the on-screen keyboard. page.keyboard_dismiss_behavior=
reaches the implicit page view.
View accepts on_refresh, the refresh_* options, on_end_reached and
end_reached_threshold. An explicit view(route:, on_refresh:) is a
registered control, so its refresh is dispatched to the handler and
acknowledged with end_refresh on the view like any scrollable.
Page#scroll_to, show_drawer, close_drawer, show_end_drawer and
close_end_drawer invoked control 1 (the Page). The Flutter Page listener
does not know these methods and answered "Unknown Page method"; the View
owns them. Like Flet, scroll_to now targets the root view and the drawer
methods the top view, which is the implicit page view when the app has
no explicit views. The drawer check follows the same view.
A page-level handler (page.on_refresh = ->(e) {}, set_view_props, the DSL
page(...) props or update(:page, ...)) went into the view props, so the
Proc itself was packed onto the wire and no handler was registered. All
of those entry points meet in assign_split_prop, which now registers a
callable on_* as a page handler and sends only an on_* flag: on the
implicit View for View events, on the Page otherwise. page.on(:x) sets
the View flag for View events too. Events the client fires on the
implicit page View (not a registered control, so they used to be
dropped) dispatch to those handlers, and a refresh is acknowledged with
end_refresh on that View.
@AdamMusa
AdamMusa force-pushed the fix/default-page-view-events branch from bd4249d to 445d23a Compare October 28, 2026 15:24
@AdamMusa
AdamMusa merged commit 37f581c into main Nov 2, 2026
12 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.

1 participant