fabulous-dev / Fabulous

Declarative UI framework for cross-platform mobile & desktop apps, using MVU and F# functional programming
https://fabulous.dev
Apache License 2.0
1.13k stars 122 forks source link

Update Scalar attributes after updating children to fix issue with invalid hierarchy #917

Closed TimLariviere closed 2 years ago

TimLariviere commented 2 years ago

When dispatching a message in a child view using a different type of message, we rely on ViewNode having both the MapMsg function set and a reference to the parent ViewNode to be able to map the child message to the app root message type.

Root (RootMsg)
    -> ChildA (ChildAMsg)
       -> GrandChild
           -> GrandGrandChild (GrandGrandChildMsg)
    -> ChildB (ChildBMsg)
       -> GrandChild
           -> GrandGrandChild (GrandGrandChildMsg)

Except during the ApplyDiff, the scalar properties (including MapMsg) were updated before the children. This could result in the GrandGrandChild to try to dispatch a message while the hierarchy is changing.

To avoid this, we first update the children and then the scalar properties.