using ObserverService throws an exception
Hi
I have a loader at the end of the page. When the user scrolls to to the end of the page, I want the loader to no more observe untill new data is loaded. And observe again once new data loaded. Here is my code:
public async Task SetupObserver()
{
endOfListObserver = await ObserverService.Create(async (entries) => {
IsIntersecting = entries.FirstOrDefault().IsIntersecting;
Console.WriteLine("IsIntersecting...");
if (!IsLoading)
{
if (IsIntersecting)
{
await endOfListObserver.Unobserve(LoaderElement);
Console.WriteLine("unobserve");
var canAddMore = await LoadData();
StateHasChanged();
if (canAddMore)
{
await endOfListObserver.Observe(LoaderElement);
Console.WriteLine("observe");
}
}
}
});
await endOfListObserver.Observe(LoaderElement);
}
html code is just
<span @ref="LoaderElement">Please wait</span>
But an error is throwned when trying to unobserve : Microsoft.JSInterop.JSException : 'An exception occurred executing JS interop: The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4.. See InnerException for more details.' InvalidOperationException : Cannot get the value of a token type 'Null' as a boolean.
Any idea ?
Hi,
Could you provide a minimal working example so it's easy to replicate this issue?
Dealing with this issue as well. Same error when trying to Unobserve. Using .NET 7 Blazor WASM. Running the basic example below is causing the error for me. Calling the below code AfterRender when FirstRender is true. Can confirm that the element exist as just observing the element works fine. Only Unobserve causes issues.
var observer = await IntersectObserverService.Create((entries) => { });
await observer.Observe(FirstImage);
await observer.Unobserve(FirstImage);
I'm currently working around this issue by calling Disconnect instead to stop observing.