Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async FetchChildAsync locks up Blazor wasm app #1566

Closed
rockfordlhotka opened this issue Apr 14, 2020 · 2 comments
Closed

Async FetchChildAsync locks up Blazor wasm app #1566

rockfordlhotka opened this issue Apr 14, 2020 · 2 comments
Assignees
Labels

Comments

@rockfordlhotka
Copy link
Member

As per MarimerLLC/cslaforum#922

Calling DataPortal.FetchAsync<ValueEdit>() on this class locks the app.

using Csla;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace BlazorApp1.Client
{
    [Serializable]
    public class ValueEdit : BusinessBase<ValueEdit>
    {
        public static readonly PropertyInfo<string> ValueProperty = RegisterProperty<string>(nameof(Value));
        public string Value
        {
            get => GetProperty(ValueProperty);
            set => SetProperty(ValueProperty, value);
        }

        public static readonly PropertyInfo<ValueEdit> ChildProperty = RegisterProperty<ValueEdit>(nameof(Child));
        public ValueEdit Child
        {
            get => GetProperty(ChildProperty);
            set => SetProperty(ChildProperty, value);
        }

        [Fetch]
        [FetchChild]
        private async Task FetchAsync([Inject] HttpClient httpClient)
        {
            var response = await httpClient.GetAsync("/api/value");
            var value = await response.Content.ReadAsStringAsync();
            using (BypassPropertyChecks)
            {
                Value = value;
                Child = await DataPortal.FetchChildAsync<ValueEdit>();
            }
        }
    }
}
@rockfordlhotka rockfordlhotka self-assigned this Apr 14, 2020
@rockfordlhotka rockfordlhotka added this to To do in Version 5.2.0 via automation Apr 14, 2020
@rockfordlhotka rockfordlhotka moved this from To do to In progress in Version 5.2.0 Apr 14, 2020
@rockfordlhotka
Copy link
Member Author

Yeah... 😳😳😳

I had an infinite loop bug in my test code - each time it fetched a child, it fetched that child's child!

So the data portal and everything works as expected - the "bug" was sitting at the keyboard.

Working code:

using Csla;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace BlazorApp1.Client
{
    [Serializable]
    public class ValueEdit : BusinessBase<ValueEdit>
    {
        public static readonly PropertyInfo<string> ValueProperty = RegisterProperty<string>(nameof(Value));
        public string Value
        {
            get => GetProperty(ValueProperty);
            set => SetProperty(ValueProperty, value);
        }

        public static readonly PropertyInfo<ValueEdit> ChildProperty = RegisterProperty<ValueEdit>(nameof(Child));
        public ValueEdit Child
        {
            get => GetProperty(ChildProperty);
            set => SetProperty(ChildProperty, value);
        }

        [Fetch]
        [FetchChild]
        private async Task FetchAsync(string name, [Inject] HttpClient httpClient)
        {
            Console.WriteLine($"entering {nameof(FetchAsync)}-{name}");
            var response = await httpClient.GetAsync("/api/value");
            var value = await response.Content.ReadAsStringAsync();
            Console.WriteLine($"after readstring {nameof(FetchAsync)}-{name}");
            using (BypassPropertyChecks)
            {
                Value = value;
                if (name != "child")
                    Child = await DataPortal.FetchChildAsync<ValueEdit>("child");
            }
            Console.WriteLine($"exiting {nameof(FetchAsync)}-{name}");
        }
    }
}

Version 5.2.0 automation moved this from In progress to Done Apr 15, 2020
@rockfordlhotka rockfordlhotka removed this from Done in Version 5.2.0 Apr 15, 2020
@github-actions
Copy link

github-actions bot commented Aug 7, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant