Don't use stale layout when view cache is invalidated in GPUI (#7914)

When a view is invalidated, we want to participate in Taffy layout with
an accurate style rather than the dummy style we use when a view is
cached. Previously, we only detected invalidation during paint. This
adds logic to layout as well to avoid using the dummy style when dirty.

Release Notes:

- N/A

---------

Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2024-02-16 19:06:11 +01:00 committed by GitHub
parent 577b244b03
commit 5df1318e75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -282,7 +282,10 @@ impl Element for AnyView {
cx: &mut ElementContext, cx: &mut ElementContext,
) -> (LayoutId, Self::State) { ) -> (LayoutId, Self::State) {
cx.with_view_id(self.entity_id(), |cx| { cx.with_view_id(self.entity_id(), |cx| {
if self.cache { if self.cache
&& !cx.window.dirty_views.contains(&self.entity_id())
&& !cx.window.refreshing
{
if let Some(state) = state { if let Some(state) = state {
let layout_id = cx.request_layout(&state.root_style, None); let layout_id = cx.request_layout(&state.root_style, None);
return (layout_id, state); return (layout_id, state);
@ -313,8 +316,6 @@ impl Element for AnyView {
&& cache_key.content_mask == cx.content_mask() && cache_key.content_mask == cx.content_mask()
&& cache_key.stacking_order == *cx.stacking_order() && cache_key.stacking_order == *cx.stacking_order()
&& cache_key.text_style == cx.text_style() && cache_key.text_style == cx.text_style()
&& !cx.window.dirty_views.contains(&self.entity_id())
&& !cx.window.refreshing
{ {
cx.reuse_view(state.next_stacking_order_id); cx.reuse_view(state.next_stacking_order_id);
return; return;