diff --git a/ReactWithDotNet/Client.cs b/ReactWithDotNet/Client.cs index a8db8d9a..e1b33d5b 100644 --- a/ReactWithDotNet/Client.cs +++ b/ReactWithDotNet/Client.cs @@ -30,6 +30,21 @@ internal static EventSenderInfo GetEventSenderInfo(ReactComponentBase reactCompo public sealed class Client { + internal Client Clone() + { + if (TaskList.Count == 0) + { + return new(_reactContext); + } + + var cloned = new Client(_reactContext); + + cloned.TaskList.AddRange(TaskList); + + return cloned; + } + + internal readonly List TaskList = new(); readonly ReactContext _reactContext; diff --git a/ReactWithDotNet/ElementSerializer.ToJsonMap.cs b/ReactWithDotNet/ElementSerializer.ToJsonMap.cs index ebd1fe15..3fe5a2bb 100644 --- a/ReactWithDotNet/ElementSerializer.ToJsonMap.cs +++ b/ReactWithDotNet/ElementSerializer.ToJsonMap.cs @@ -1,8 +1,6 @@ using System.Collections; -using System.Collections.Concurrent; using System.Diagnostics; using System.Reflection; -using System.Text.Json.Serialization; namespace ReactWithDotNet; @@ -603,14 +601,7 @@ ReactComponentBase cloneComponent() if (component._client is not null) { - if (component._client.TaskList.Count == 0) - { - component._client = new(component.Context); - } - else - { - component._client = ReflectionHelper.DeepCopy(component._client); - } + component._client = component._client.Clone(); } return component;