Skip to content

Commit

Permalink
fix: prevent building overlay with stale layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksenger committed May 11, 2022
1 parent d4ed8af commit 3be8f6e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
36 changes: 33 additions & 3 deletions lazy/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,38 @@ where
let mut local_messages = Vec::new();
let mut local_shell = Shell::new(&mut local_messages);

if self
.instance
.state
.borrow()
.as_ref()
.and_then(|state| state.borrow_cache().as_ref())
.and_then(|cache| cache.borrow_overlay().as_ref())
.is_none()
{
let component =
self.instance.state.take().unwrap().into_heads().component;

self.instance.state = RefCell::new(Some(
StateBuilder {
component,
message: PhantomData,
cache_builder: |state| {
Some(
CacheBuilder {
element: state.view(),
overlay_builder: |element| {
element.overlay(layout, renderer)
},
}
.build(),
)
},
}
.build(),
));
}

let event_status = self
.with_overlay_mut_maybe(|overlay| {
overlay.on_event(
Expand Down Expand Up @@ -410,9 +442,7 @@ where
Some(
CacheBuilder {
element: state.view(),
overlay_builder: |element| {
element.overlay(layout, renderer)
},
overlay_builder: |_| None,
}
.build(),
)
Expand Down
40 changes: 30 additions & 10 deletions lazy/src/pure/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,35 @@ where
let mut local_messages = Vec::new();
let mut local_shell = Shell::new(&mut local_messages);

if self
.overlay
.as_ref()
.and_then(|overlay| overlay.borrow_overlay().as_ref())
.is_none()
{
let overlay = self.overlay.take().unwrap().into_heads();

self.overlay = Some(
OverlayBuilder {
instance: overlay.instance,
instance_ref_builder: |instance| instance.state.borrow(),
tree: overlay.tree,
types: PhantomData,
overlay_builder: |instance, tree| {
instance
.as_ref()
.unwrap()
.borrow_element()
.as_ref()
.unwrap()
.as_widget()
.overlay(&mut tree.children[0], layout, renderer)
},
}
.build(),
);
}

let event_status = self
.with_overlay_mut_maybe(|overlay| {
overlay.on_event(
Expand Down Expand Up @@ -464,16 +493,7 @@ where
instance_ref_builder: |instance| instance.state.borrow(),
tree: overlay.tree,
types: PhantomData,
overlay_builder: |instance, tree| {
instance
.as_ref()
.unwrap()
.borrow_element()
.as_ref()
.unwrap()
.as_widget()
.overlay(&mut tree.children[0], layout, renderer)
},
overlay_builder: |_, _| None,
}
.build(),
);
Expand Down

0 comments on commit 3be8f6e

Please sign in to comment.