From 0e717c8f57d2d3ae23ee77502ceeea26d8d27673 Mon Sep 17 00:00:00 2001 From: Ben Date: Tue, 4 Nov 2025 17:06:11 +0800 Subject: [PATCH] Fix #5774: remove duplicated radzen dialog delegate handlers. --- .../TextEditors/Radzen/RadzenTextEditor.razor | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Oqtane.Client/Modules/Controls/TextEditors/Radzen/RadzenTextEditor.razor b/Oqtane.Client/Modules/Controls/TextEditors/Radzen/RadzenTextEditor.razor index 5cfdb420..8e0d347e 100644 --- a/Oqtane.Client/Modules/Controls/TextEditors/Radzen/RadzenTextEditor.razor +++ b/Oqtane.Client/Modules/Controls/TextEditors/Radzen/RadzenTextEditor.razor @@ -3,6 +3,7 @@ @using System.Text.RegularExpressions @using Radzen @using Radzen.Blazor +@using System.Reflection @namespace Oqtane.Modules.Controls @inherits ModuleControlBase @@ -93,6 +94,17 @@ } await _interop.SetBackgroundColor(_editor.Element, backgroundColor); } + + var subscribers = GetEventSubscribers(DialogService, "OnOpen"); + var dialogSubscibers = subscribers?.Where(s => s.Method.DeclaringType == typeof(RadzenDialog)) ?? Enumerable.Empty(); + if (dialogSubscibers.Count() > 1) + { + //clean the event to avoid multiple RadzenDialog instances subscribing to the event + dialogSubscibers.Skip(1).ToList().ForEach(s => + { + DialogService.OnOpen -= s as Action, DialogOptions>; + }); + } } } @@ -212,4 +224,23 @@ { await _interop.UpdateDialogLayout(_editor.Element); } + + private Delegate[] GetEventSubscribers(object target, string eventName) + { + var type = target.GetType(); + var eventField = type.GetField(eventName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + + if (eventField == null) + { + return null; + } + + var eventDelegate = eventField.GetValue(target) as Delegate; + if (eventDelegate == null) + { + return new Delegate[0]; + } + + return eventDelegate.GetInvocationList(); + } } \ No newline at end of file