Skip to content

Commit 3570efe

Browse files
MarcelRoozekranstpeczek
authored andcommitted
Fix: Catch JSDisconnectedExcpetion
1 parent 7724407 commit 3570efe

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Blazor.BroadcastChannel/BroadcastChannelService.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ public async Task AddMessageEventListener(BroadcastChannel channel)
4646

4747
public async ValueTask DisposeAsync()
4848
{
49-
if (_moduleTask.IsValueCreated)
49+
try
5050
{
51-
IJSObjectReference module = await _moduleTask.Value;
52-
await module.DisposeAsync();
51+
if (_moduleTask.IsValueCreated)
52+
{
53+
IJSObjectReference module = await _moduleTask.Value;
54+
await module.DisposeAsync();
55+
}
56+
}
57+
catch (JSDisconnectedException)
58+
{
59+
// When disposing the module, the JS runtime may be disconnected.
5360
}
5461
}
5562
}

0 commit comments

Comments
 (0)