BlazorIntersectionObserver icon indicating copy to clipboard operation
BlazorIntersectionObserver copied to clipboard

Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'

Open indieza opened this issue 3 years ago • 6 comments

Hello,

I got the following error in the console after the execution of the logic after checking is the current item is observed.

Microsoft.JSInterop.JSException: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'.
TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'.

I apply the code which I use.

<div @ref="@this.Reference">
    Some data
</div>

public ElementReference Reference { get; set; } = new ElementReference(Guid.NewGuid().ToString());

await ObserverService.Observe(Reference, async (entries) =>
{
    if (entries.FirstOrDefault().IsIntersecting)
    {
        // Login execution
    }
});

Regards, Simeon Valev

indieza avatar Sep 20 '22 13:09 indieza

I'm getting this error as well on Blazor WASM on its initial load (no issue with same impl on Blazor Server).

Tracked the issue down to this observeElement() function being passed a `null element:

https://github.com/ljbc1994/BlazorIntersectionObserver/blob/9e1cde8f2a79a08f3e67917b5a40a49ddccc4f46/src/Ljbc1994.Blazor.IntersectionObserver/src/index.ts#L89

Although I've logged the element to the dev console, i.e:

js.InvokeVoidAsync("console.log", elementRef)

Before observing it with:

await ObserverService.Observe(elementRef,...)

Where logs show that it always has the element reference, but for some reason it comes across as null in JS function.

mythz avatar Nov 08 '22 10:11 mythz

I have the same issue, with the same error occuring on blazor WASM and not on blazor server, even if I verify the ElementReference before observing: public async Task SetupObserver(ElementReference elementRef) { if (elementRef is ElementReference && elementRef != null) { _imageObserver = await ObserverService.Observe(elementRef.Value, (entries) => { //logic }); } }

janholbrouck avatar Dec 18 '22 21:12 janholbrouck

Has anyone found a solution to this issue? I'm able to reproduce this 100% of the time by changing page just as an observed item is being loaded in. For reference I am using the component version and not the service setup.

axekan avatar Jan 12 '23 10:01 axekan

Same issue here. In my case, I am experiencing it on Blazor Server.

A pity, I really would love this to work.

alelom avatar Jul 22 '23 07:07 alelom

Hey, could you provide a minimal working example of this so I can replicate this?

Also, what version of dotnet are you using?

ljbc1994 avatar Jul 22 '23 12:07 ljbc1994

I tested this on NET7, Blazor Server.

A minimal working example is: Nevermind, I had one that I used to test, upon reopening VS I could not replicate the issue anymore!

alelom avatar Jul 22 '23 13:07 alelom