gui: reclaim layout callback lifetimes#2
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2b94d219a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
c2b94d2 to
593dbfd
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 593dbfdba7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
593dbfd to
0478d8a
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0478d8a7dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0478d8a to
7fabf3f
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7fabf3ffcf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| window.layout = window.compose_layout(mut view) | ||
| view_clear(mut view) | ||
| }) or { panic(err) } | ||
| window.reclaim_old_layout_callbacks() |
There was a problem hiding this comment.
Pin async CRUD callbacks before reclaiming layout closures
With this reclaim now running after every layout pass, a data grid CRUD save can outlive the one retained layout frame: view_data_grid_crud.v:589-594 starts a background mutation from the Save click and captures on_crud_error, on_rows_change, and on_selection_change into the queued completion without any pin/suspend. Since event_fn requests a layout refresh after the click, any save that takes more than a frame can later call callbacks that were allocated in the old layout lifetime and have already been reclaimed, leading to use-after-free or dropped/corrupt completion handling.
Useful? React with 👍 / 👎.
| parent_id: state.parent_id | ||
| }) | ||
| if drag_reorder_dispatch_drop(drag_key, mut w) { | ||
| w.animate_layout(LayoutTransitionCfg{}) |
There was a problem hiding this comment.
Capture reorder snapshots before dispatching drop
In the drop path, drag_reorder_dispatch_drop invokes the widget handler and drag_reorder_apply_drop, which calls the user's on_reorder, before this snapshot is captured. If an on_reorder callback synchronously rebuilds or replaces the view (for example by calling w.update() or w.update_view()), animate_layout() captures the already-updated layout, so the final drop loses its FLIP transition. The previous code captured before on_reorder, which matches the ordering required by animation_layout.v.
Useful? React with 👍 / 👎.
| window.suspend_layout_callback_tracking(fn [source, req, grid_id, next_request_id, caps, mut window] () { | ||
| spawn fn [source, req, grid_id, next_request_id, caps] (mut w Window) { |
There was a problem hiding this comment.
Pin inline data-source callbacks until fetch completion
This suspend only detaches the newly-created spawn wrapper; it does not keep closures that are already stored inside source alive. If a view constructs a GridOrmDataSource or custom DataGridDataSource inline with a fetch_fn/method closure capturing layout locals, the background source.fetch_data(req) can run after the next layout reclaim and invoke a reclaimed closure. The same pattern exists in the list-box source path, so these async source requests need a reclaim pin until the fetch queues its result, or the source callbacks need to be copied outside the layout lifetime before this point.
Useful? React with 👍 / 👎.
Summary
This uses the closure lifetime/reclaim API from vlang/v#27483 to reclaim transient layout callbacks in v-gui.
Window.update()now builds each layout tree inside a layout callback lifetime frame, keeps the current layout alive, and reclaims old frame-owned closure contexts after the new layout has been installed.Persistent callbacks created during layout, such as animations or hover-created callbacks, are kept outside the transient reclaim scope.
Changes
Window.update().Dependency
This PR depends on vlang/v#27483.
It should not be merged until vlang/v#27483 is merged and v-gui CI uses a V compiler that includes the closure lifetime/reclaim API.
Tests