diff --git a/CHANGELOG.md b/CHANGELOG.md index c3c28afa5..ffb2b91c7 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_ +## [3.0.0-pre4] - 2024-04-16 + +### Changed +- Find the component data key in ScalarAttributes by @edgarfgp (https://github.com/fabulous-dev/Fabulous/pull/1076) + ## [3.0.0-pre3] - 2024-04-12 ### Changed @@ -125,7 +130,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/3.0.0-pre3...HEAD +[unreleased]: https://github.com/fabulous-dev/Fabulous/compare/3.0.0-pre4...HEAD +[3.0.0-pre4]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre4 [3.0.0-pre3]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre3 [3.0.0-pre2]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre2 [3.0.0-pre1]: https://github.com/fabulous-dev/Fabulous/releases/tag/3.0.0-pre1 diff --git a/src/Fabulous/MvuComponent.fs b/src/Fabulous/MvuComponent.fs index a54c8d741..5089159b0 100644 --- a/src/Fabulous/MvuComponent.fs +++ b/src/Fabulous/MvuComponent.fs @@ -99,12 +99,25 @@ module MvuComponent = let canReuseMvuComponent (prev: Widget) (curr: Widget) = let prevData = match prev.ScalarAttributes with - | ValueSome attrs when attrs.Length > 0 -> attrs[0].Value :?> MvuComponentData + | ValueSome attrs -> + let scalarAttrsOpt = + attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + + match scalarAttrsOpt with + | None -> failwithf "Component widget must have a body" + | Some value -> value.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 + | ValueSome attrs -> + let scalarAttrsOpt = + attrs |> Array.tryFind(fun scalarAttr -> scalarAttr.Key = Data.Key) + + match scalarAttrsOpt with + | None -> failwithf "Component widget must have a body" + | Some value -> value.Value :?> MvuComponentData | _ -> failwith "Component widget must have a body" // NOTE: Somehow using = here crashes the app and prevents debugging...