From 565b70f3e004459ef100cd8e7f26642a07bb9682 Mon Sep 17 00:00:00 2001 From: Saleh Yusefnejad Date: Wed, 23 Oct 2024 18:20:43 +0330 Subject: [PATCH] fix(blazorui): resolve issues of disposing BitDataGrid and BitFileUpload #8986 (#8987) --- .../Components/DataGrid/BitDataGrid.razor.cs | 6 ++++++ .../Components/Inputs/FileUpload/BitFileUpload.razor.cs | 6 ++++++ .../Platforms/Android/MainActivity.cs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/BitDataGrid.razor.cs b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/BitDataGrid.razor.cs index 58a41f2b63..d8a181b483 100644 --- a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/BitDataGrid.razor.cs +++ b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/BitDataGrid.razor.cs @@ -416,6 +416,12 @@ public async ValueTask DisposeAsync() // The JS side may routinely be gone already if the reason we're disposing is that // the client disconnected. This is not an error. } + catch(JSException ex) + { + // it seems it's safe to just ignore this exception here. + // otherwise it will blow up the MAUI app in a page refresh for example. + Console.WriteLine(ex.Message); + } } private void CloseColumnOptions() diff --git a/src/BlazorUI/Bit.BlazorUI/Components/Inputs/FileUpload/BitFileUpload.razor.cs b/src/BlazorUI/Bit.BlazorUI/Components/Inputs/FileUpload/BitFileUpload.razor.cs index daed86ab61..6ac051a6f0 100644 --- a/src/BlazorUI/Bit.BlazorUI/Components/Inputs/FileUpload/BitFileUpload.razor.cs +++ b/src/BlazorUI/Bit.BlazorUI/Components/Inputs/FileUpload/BitFileUpload.razor.cs @@ -692,6 +692,12 @@ protected virtual async ValueTask DisposeAsync(bool disposing) await _dropZoneRef.DisposeAsync(); } catch (JSDisconnectedException) { } // we can ignore this exception here + catch (JSException ex) + { + // it seems it's safe to just ignore this exception here. + // otherwise it will blow up the MAUI app in a page refresh for example. + Console.WriteLine(ex.Message); + } } if (_dotnetObj is not null) diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Maui/Platforms/Android/MainActivity.cs b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Maui/Platforms/Android/MainActivity.cs index 4370f26922..5f00e79f9a 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Maui/Platforms/Android/MainActivity.cs +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Maui/Platforms/Android/MainActivity.cs @@ -3,7 +3,7 @@ namespace Bit.BlazorUI.Demo.Client.Maui.Platforms.Android; -[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, +[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTask, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] public class MainActivity : MauiAppCompatActivity {