From e89681af84cb2a6ef708d414fb963f58b449b30a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20Larivi=C3=A8re?= Date: Mon, 19 Feb 2024 16:53:39 +0100 Subject: [PATCH 1/2] Destroy component on arg change --- src/Fabulous/MvuComponent.fs | 15 +++++++++++++++ src/Fabulous/View.fs | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/Fabulous/MvuComponent.fs b/src/Fabulous/MvuComponent.fs index a93978a72..502e278c5 100644 --- a/src/Fabulous/MvuComponent.fs +++ b/src/Fabulous/MvuComponent.fs @@ -1,5 +1,6 @@ namespace Fabulous +open System open System.Runtime.CompilerServices [] @@ -88,6 +89,20 @@ module MvuComponent = let Data = Attributes.defineSimpleScalar "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ()) + + let canReuseMvuComponent (prev: Widget) (curr: Widget) = + let prevData = + match prev.ScalarAttributes with + | ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData + | _ -> failwith "Component widget must have a body" + + let currData = + match curr.ScalarAttributes with + | ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData + | _ -> failwith "Component widget must have a body" + + // NOTE: Somehow using = here crashes the app and prevents debugging... + Object.Equals(prevData.Arg, currData.Arg) /// Delegate used by the MvuComponentBuilder to compose a component body /// It will be aggressively inlined by the compiler leaving no overhead, only a pure function that returns a WidgetBuilder diff --git a/src/Fabulous/View.fs b/src/Fabulous/View.fs index bd0813e1f..08acdaa96 100644 --- a/src/Fabulous/View.fs +++ b/src/Fabulous/View.fs @@ -8,6 +8,8 @@ module ViewHelpers = false else if (prevKey = Memo.MemoWidgetKey) then Memo.canReuseMemoizedWidget prevWidget currWidget + else if (prevKey = MvuComponent.WidgetKey) then + MvuComponent.canReuseMvuComponent prevWidget currWidget else true From 4148e18dc10cf7c7c17d5866b3e884180ccbd46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9=20Larivi=C3=A8re?= Date: Mon, 19 Feb 2024 16:55:56 +0100 Subject: [PATCH 2/2] Update changelog + format code --- CHANGELOG.md | 8 +++++++- src/Fabulous/MvuComponent.fs | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3864c95b4..0e5e6468f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 _No unreleased changes_ +## [2.5.0-pre11] - 2024-02-19 + +### Fixed +- Recreate component on arg change by @TimLariviere (https://github.com/fabulous-dev/Fabulous/pull/1069) + ## [2.5.0-pre10] - 2024-02-19 ### Fixed @@ -105,7 +110,8 @@ _No unreleased changes_ ### Changed - Fabulous.XamarinForms & Fabulous.MauiControls have been moved been out of the Fabulous repository. Find them in their own repositories: [https://github.com/fabulous-dev/Fabulous.XamarinForms](https://github.com/fabulous-dev/Fabulous.XamarinForms) / [https://github.com/fabulous-dev/Fabulous.MauiControls](https://github.com/fabulous-dev/Fabulous.MauiControls) -[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.5.0-pre10...HEAD +[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/2.5.0-pre11...HEAD +[2.5.0-pre11]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre11 [2.5.0-pre10]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre10 [2.5.0-pre9]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre9 [2.5.0-pre8]: https://github.com/fabulous-dev/Fabulous/releases/tag/2.5.0-pre8 diff --git a/src/Fabulous/MvuComponent.fs b/src/Fabulous/MvuComponent.fs index 502e278c5..39b9d3886 100644 --- a/src/Fabulous/MvuComponent.fs +++ b/src/Fabulous/MvuComponent.fs @@ -89,18 +89,18 @@ module MvuComponent = let Data = Attributes.defineSimpleScalar "MvuComponent_Data" ScalarAttributeComparers.noCompare (fun _ _ _ -> ()) - + let canReuseMvuComponent (prev: Widget) (curr: Widget) = let prevData = match prev.ScalarAttributes with | ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData | _ -> failwith "Component widget must have a body" - + let currData = match curr.ScalarAttributes with | ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData | _ -> failwith "Component widget must have a body" - + // NOTE: Somehow using = here crashes the app and prevents debugging... Object.Equals(prevData.Arg, currData.Arg)