Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using ObserverService throws an exception #50

Open
EnjoyMachine opened this issue Jun 26, 2023 · 2 comments
Open

using ObserverService throws an exception #50

EnjoyMachine opened this issue Jun 26, 2023 · 2 comments

Comments

@EnjoyMachine
Copy link

EnjoyMachine commented Jun 26, 2023

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 ?

@EnjoyMachine EnjoyMachine changed the title using ObserverService throws an execption using ObserverService throws an exception Jun 26, 2023
@ljbc1994
Copy link
Owner

Hi,

Could you provide a minimal working example so it's easy to replicate this issue?

@andrewpbaer
Copy link

andrewpbaer commented Nov 15, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants