Repository navigation
Description
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_dialogscontainer. When the container's list changed, a barepage.updatesends the same whole-list replace throughsend_changed_control_patches. - Engine (
packages/ruflet/lib/src/models/control.dart,applyPatch): a replace op runs_transformIfControl, which callsControl.fromMap. That creates a new instance for every map and re-registers its id incontrolsIndex. - The presented route belongs to the instance:
- Engine:
widgets/control_route.dartkeeps anExpandokeyed by theControl. - Template's vendored engine:
alert_dialog.dartkeeps_openin that instance's properties.
- Engine:
- So the new instance presents a second copy. The old route stays on screen. A later
open: falsefrom 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:
- A second overlay while one is open. This covers
show_dialog,show_snack_bar,show_bottom_sheet,open, and the slot settersdialog=,snack_bar=andbottom_sheet=. The open dialog is re-sent withopen: true. close(a); open(s)in one handler. Ruby sends104 open:false, then the container[A(open:false), S]. When both land in the same frame, the old A never seesopen: false. With a frame between them, A closes. This case depends on timing.- A bare
page.updateafter the user dismissed one of two stacked dialogs.- The client's
update_control open:falsemakes Ruby drop B from its list without sending anything. - The next bare
page.updatere-sends the rest:103 [[0],[0,0,"controls",[A(open:true)]]]. A is duplicated. - The
dismissevent does not push, becauseremove_dialog_trackingalready ran on theupdate_control.
- The client's
- 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
_dialogsand closes correctly. In that probe,101 controls:[]is the_overlaycontainer, 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 wholeclose_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).
-
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. -
A dialog that left the list while it is closing stays on the client until the client reports it closed (
update_control open:falseordismiss). This covers hot reload and a dialog slot cleared byclosein the same handler. Removing it in the same frame as itsopen: falsewould 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. -
Ruby forgets that record whenever the whole container goes to a client:
- the
register_clientreply - a view patch that mounts the container
prepare_for_reconnect!
Index-based ops therefore never go stale.
- the
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