Skip to content

Commit 8a1393a

Browse files
committed
Fix: HelperScriptService caused unnecessarily exceptions
1 parent 1110bf4 commit 8a1393a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

AwesomeBlazorBrowser/HelperScriptService.cs

+14-10
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,36 @@ private async ValueTask<IJSObjectReference> GetHelperAsync()
2121

2222
public async ValueTask InstallHashWatcherAsync()
2323
{
24-
var helpder = await this.GetHelperAsync();
25-
await helpder.InvokeVoidAsync("installHashWatcher");
24+
var helper = await this.GetHelperAsync();
25+
await helper.InvokeVoidAsync("installHashWatcher");
2626
}
2727

2828
public async ValueTask ScrollToAnchorAsync(string anchorName, bool smooth, bool changeUrl = false)
2929
{
30-
var helpder = await this.GetHelperAsync();
31-
await helpder.InvokeVoidAsync("scrollToAnchor", anchorName.TrimStart('#'), smooth, changeUrl);
30+
var helper = await this.GetHelperAsync();
31+
await helper.InvokeVoidAsync("scrollToAnchor", anchorName.TrimStart('#'), smooth, changeUrl);
3232
}
3333

3434
public async ValueTask<Theme> GetCurrentThemeAsync()
3535
{
36-
var helpder = await this.GetHelperAsync();
37-
var themeStr = await helpder.InvokeAsync<string>("getCurrentTheme");
36+
var helper = await this.GetHelperAsync();
37+
var themeStr = await helper.InvokeAsync<string>("getCurrentTheme");
3838
return ThemeExtension.Parse(themeStr);
3939
}
4040

4141
public async ValueTask SetCurrentThemeAsync(Theme theme)
4242
{
43-
var helpder = await this.GetHelperAsync();
44-
await helpder.InvokeVoidAsync("setCurrentTheme", theme.ToKebabCase());
43+
var helper = await this.GetHelperAsync();
44+
await helper.InvokeVoidAsync("setCurrentTheme", theme.ToKebabCase());
4545
}
4646

4747
public async ValueTask DisposeAsync()
4848
{
49-
var helpder = await this.GetHelperAsync();
50-
await helpder.DisposeAsync();
49+
if (this._Helper is not null)
50+
{
51+
try { await this._Helper.DisposeAsync(); }
52+
catch (JSDisconnectedException) { }
53+
finally { this._Helper = null; }
54+
}
5155
}
5256
}

0 commit comments

Comments
 (0)