Skip to content

Dialogs layer is re-sent as a whole list: a second overlay duplicates an open dialog that then cannot close; close+show and hot reload strand a modal #138

Closed

Description

@AdamMusa

Summary

Every change to the page's Dialogs layer (_dialogs.controls) is sent as one replace op that carries the whole list again, including dialogs that are already open. On the client that list becomes new Control instances, and the route an open dialog presented belongs to the old instance. The user then sees a second copy of the open dialog, and the first copy can no longer be closed from Ruby.

Cause

  • Ruby: Page#push_dialogs_update! always sends [[0], [0, 0, "controls", <whole list>]] to the _dialogs container. When the container's list changed, a bare page.update sends the same whole-list replace through send_changed_control_patches.
  • Engine (packages/ruflet/lib/src/models/control.dart, applyPatch): a replace op runs _transformIfControl, which calls Control.fromMap. That creates a new instance for every map and re-registers its id in controlsIndex.
  • The presented route belongs to the instance:
    • Engine: widgets/control_route.dart keeps an Expando keyed by the Control.
    • Template's vendored engine: alert_dialog.dart keeps _open in that instance's properties.
  • So the new instance presents a second copy. The old route stays on screen. A later open: false from Ruby is addressed by id, now resolves to the new instance, and the old copy is stuck.

Reproduce (Ruby wire)

Tested on main a668af6. The wire is identical on 0.0.23.

page.show_dialog(a)
# patch_control 103 [[0],[0,0,"controls",[{AlertDialog _i:104 ... "open":true}]]]
page.show_snack_bar(s)   # while A is open
# patch_control 103 [[0],[0,0,"controls",[{AlertDialog _i:104 ... "open":true},{SnackBar _i:106 ...}]]]

All of these send the whole list again:

  1. A second overlay while one is open. This covers show_dialog, show_snack_bar, show_bottom_sheet, open, and the slot setters dialog=, snack_bar= and bottom_sheet=. The open dialog is re-sent with open: true.
  2. close(a); open(s) in one handler. Ruby sends 104 open:false, then the container [A(open:false), S]. When both land in the same frame, the old A never sees open: false. With a frame between them, A closes. This case depends on timing.
  3. A bare page.update after the user dismissed one of two stacked dialogs.
    • The client's update_control open:false makes Ruby drop B from its list without sending anything.
    • The next bare page.update re-sends the rest: 103 [[0],[0,0,"controls",[A(open:true)]]]. A is duplicated.
    • The dismiss event does not push, because remove_dialog_tracking already ran on the update_control.
  4. Hot reload when the reloaded app block shows an overlay.
    • Server#reload_app! closes the open dialogs first (104 open:false).
    • If the re-run block then shows a snack bar or a dialog, the whole-list replace removes the closing modal in the same frame. Its route is never popped, and it stays over the reloaded app.
    • A plain reload, where the block shows no overlay, does not touch _dialogs and closes correctly. In that probe, 101 controls:[] is the _overlay container, not _dialogs (103).

Client evidence

These are widget tests that apply the exact patches above with Control.applyPatch, as RufletBackend does. They ran on engine codex/engine-initialization 00d1df3c and on the vendored engine in template main 8b08569, which every published gem fetches at build time. Material and Cupertino gave the same results.

The table counts visible copies of "Dialog A" after each step. The "List ops" column shows the same scenarios sent as add/remove ops on _dialogs.controls instead of a whole-list replace.

Scenario Expected Today List ops
show(A), show(snack), close(A) 1, 1, 0 1, 2, 1 1, 1, 0
show(A, modal), show(B), close(B), close(A) 1, 1, 0 1, 2, 1 1, 1, 0
close(A) and open(snack) in one frame 0 1 0
Material: snack open, then a dialog opens (snack still shown after 6 s) 0 1 (re-queued) 0

Expected: each overlay is on screen once and closes when Ruby closes it.

Actual: an open overlay is duplicated whenever the list changes, and one copy cannot be closed. On iOS a modal copy blocks the app.

Location

  • packages/ruflet_core/lib/ruflet_ui/ruflet/page.rb:
    • push_dialogs_update!
    • send_changed_control_patches, where a changed container list is re-sent whole
    • close_dialog, whose comment already notes that a replace recreates the control
  • packages/ruflet_server/lib/ruflet/server.rb: reload_app!

Proposal

This is a Ruby-only fix. The engine head and the live template already apply list add, remove and move ops (models/control.dart, applyPatch).

  1. Ruby remembers the list it last published to the client's _dialogs.controls. It sends add, remove or move list ops, so a dialog that stays in the list is never re-sent. That dialog's own changes go out as its own patches.

  2. A dialog that left the list while it is closing stays on the client until the client reports it closed (update_control open:false or dismiss). This covers hot reload and a dialog slot cleared by close in the same handler. Removing it in the same frame as its open: false would drop the close. A dialog the client reported closed is removed, and it is added again as a new control when it is shown again, as today.

  3. Ruby forgets that record whenever the whole container goes to a client:

    • the register_client reply
    • a view patch that mounts the container
    • prepare_for_reconnect!

    Index-based ops therefore never go stale.

Public API is unchanged: show_dialog, open, close, the slot setters and the events behave as before. Only the shape of the _dialogs container patches changes. Flet also sends this list as a diff, so this matches Flet.

Engine-side hardening, such as keyed overlay widgets or keeping the instance on a same-id replace, is a separate follow-up.

Activity

  1. added
    bug
    on Nov 21, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions