Skip to content

Commit

Permalink
fix: Avoid trigering side effects in orphan nodes updates (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 authored Oct 6, 2024
1 parent 5406453 commit 8087d26
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
4 changes: 3 additions & 1 deletion crates/state/src/accessibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,9 @@ impl State<CustomAttributeValues> for AccessibilityNodeState {

*self = accessibility;

if changed {
let is_orphan = node_view.height() == 0 && node_view.node_id() != *root_id;

if changed && !is_orphan {
// Assign an accessibility ID if none was passed but the node has a valid builder
//
// In our case, builder will be `None` if the node's tag cannot be added to accessibility
Expand Down
6 changes: 5 additions & 1 deletion crates/state/src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use freya_native_core::{
State,
},
tags::TagName,
NodeId,
SendAnyMap,
};
use freya_native_core_macro::partial_derive_state;
Expand Down Expand Up @@ -151,6 +152,7 @@ impl State<CustomAttributeValues> for CursorState {
_children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
context: &SendAnyMap,
) -> bool {
let root_id = context.get::<NodeId>().unwrap();
let paragraphs = context.get::<Arc<Mutex<ParagraphElements>>>().unwrap();
let compositor_dirty_nodes = context.get::<Arc<Mutex<CompositorDirtyNodes>>>().unwrap();
let mut cursor = parent.map(|(p,)| p.clone()).unwrap_or_default();
Expand All @@ -162,7 +164,9 @@ impl State<CustomAttributeValues> for CursorState {
}
let changed = &cursor != self;

if changed && CursorMode::Editable == cursor.mode {
let is_orphan = node_view.height() == 0 && node_view.node_id() != *root_id;

if changed && CursorMode::Editable == cursor.mode && !is_orphan {
if let Some((tag, cursor_ref)) = node_view.tag().zip(cursor.cursor_ref.as_ref()) {
if *tag == TagName::Paragraph {
paragraphs
Expand Down
5 changes: 4 additions & 1 deletion crates/state/src/font_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ impl State<CustomAttributeValues> for FontStyleState {
_children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
context: &SendAnyMap,
) -> bool {
let root_id = context.get::<NodeId>().unwrap();
let torin_layout = context.get::<Arc<Mutex<Torin<NodeId>>>>().unwrap();
let compositor_dirty_nodes = context.get::<Arc<Mutex<CompositorDirtyNodes>>>().unwrap();

Expand All @@ -290,7 +291,9 @@ impl State<CustomAttributeValues> for FontStyleState {

let changed = &font_style != self;

if changed {
let is_orphan = node_view.height() == 0 && node_view.node_id() != *root_id;

if changed && !is_orphan {
torin_layout.lock().unwrap().invalidate(node_view.node_id());
compositor_dirty_nodes
.lock()
Expand Down
6 changes: 5 additions & 1 deletion crates/state/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use freya_native_core::{
NodeMaskBuilder,
State,
},
NodeId,
SendAnyMap,
};
use freya_native_core_macro::partial_derive_state;
Expand Down Expand Up @@ -75,6 +76,7 @@ impl State<CustomAttributeValues> for LayerState {
return false;
}

let root_id = context.get::<NodeId>().unwrap();
let layers = context.get::<Arc<Mutex<Layers>>>().unwrap();
let inherited_layer = parent.map(|(p,)| p.layer_for_children).unwrap_or(0i16);

Expand All @@ -91,7 +93,9 @@ impl State<CustomAttributeValues> for LayerState {

let changed = &layer_state != self;

if changed {
let is_orphan = node_view.height() == 0 && node_view.node_id() != *root_id;

if changed && !is_orphan {
layers
.lock()
.unwrap()
Expand Down
5 changes: 4 additions & 1 deletion crates/state/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl State<CustomAttributeValues> for LayoutState {
_children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
context: &SendAnyMap,
) -> bool {
let root_id = context.get::<NodeId>().unwrap();
let torin_layout = context.get::<Arc<Mutex<Torin<NodeId>>>>().unwrap();
let compositor_dirty_nodes = context.get::<Arc<Mutex<CompositorDirtyNodes>>>().unwrap();

Expand All @@ -237,7 +238,9 @@ impl State<CustomAttributeValues> for LayoutState {

let changed = layout != *self;

if changed {
let is_orphan = node_view.height() == 0 && node_view.node_id() != *root_id;

if changed && !is_orphan {
torin_layout.lock().unwrap().invalidate(node_view.node_id());
compositor_dirty_nodes
.lock()
Expand Down
5 changes: 4 additions & 1 deletion crates/state/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl State<CustomAttributeValues> for TransformState {
_children: Vec<<Self::ChildDependencies as Dependancy>::ElementBorrowed<'a>>,
context: &SendAnyMap,
) -> bool {
let root_id = context.get::<NodeId>().unwrap();
let compositor_dirty_nodes = context.get::<Arc<Mutex<CompositorDirtyNodes>>>().unwrap();
let inherited_transform = parent.map(|(p,)| p.clone()).unwrap_or_default();

Expand All @@ -101,7 +102,9 @@ impl State<CustomAttributeValues> for TransformState {

let changed = transform_state != *self;

if changed {
let is_orphan = node_view.height() == 0 && node_view.node_id() != *root_id;

if changed && !is_orphan {
compositor_dirty_nodes
.lock()
.unwrap()
Expand Down

0 comments on commit 8087d26

Please sign in to comment.