-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: prevent building component overlay with stale layout #1341
fix: prevent building component overlay with stale layout #1341
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
I think the root cause of the issue here is in the UserInterface::update
implementation. Specifically, we are not relayouting the base
layer when an overlay invalidates the layout through a Shell
, causing the layout to be stale for further events.
I have tried to fix this in 296e157. I needed to rewrite the code to use a for
loop instead of iterators as well as use ManuallyDrop
to please the borrow checker, but it seems to be happy in the end.
Could you test if these changes fix the issue?
That explanation makes sense, and the solution looks good! I had to make one small change in order for it to fix the issue though: Since the component overlay will always invalidate the layout when there are local messages produced in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Less code to worry about!
Let's merge 🚢
fix: prevent building component overlay with stale layout
In the implementation of
on_event
for a component's overlay (both pure and impure), after processing local messages which may mutate the state and in turn alter the output ofComponent::view
, the cached element and overlay must be rebuilt. Currently, it is rebuilt with a layout tree which is potentially stale, because the shape of the layout tree is dependent upon the cached element which may have changed.I've added a preliminary fix here, which is to rebuild the cached element only after processing any local messages, then attempt to rebuild the overlay at the beginning of
on_event
if it is absent.I'll open this as a draft because it feels a bit odd to intentionally leave the cached overlay element as
None
afteron_event
. I haven't yet thought of another way to resolve this though.