Open Xeevis opened 3 years ago
Hey thanks for raising..
Is this coming from the IntersectionObserve
component or a custom component?
We do this here:
We also have it as a task for invocation:
Hello, I've looked at this more closely and in my case it's the IIntersectionObserverService
, which can't be injected directly because of JsInterop call in constructor
@inject IIntersectionObserverService ObserverService
So what I did instead was to inject IServiceProvider
and retrieve this service in OnAfterRender()
private IIntersectionObserverService observerService;
[Inject]
private IServiceProvider ServiceProvider { get; set; }
public IntersectionObserver Observer { get; internal set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
this.observerService ??= this.ServiceProvider.GetRequiredService<IIntersectionObserverService>();
this.Observer = await this.observerService.Observe(this.elementRef, (entries) =>
{
//(...)
});
}
}
Perhaps it would be worth a mention in README?
Thanks for looking into this @Xeevis.
I'll spend some more time checking this out to see if there's anything I can do. If not, I'll add this to the readme.
Thanks!
When using ASP.NET Core hosted Blazor WebAssembly app it's possible to make use of server prerendering. With this technique first user request is responded to by server instantaneously with full page html. This is useful for SEO and fast content delivery while app is still downloading in the background. Since prerendering happens only on the server with no connection to the browser, it's invalid to call any JS Interop at that time.
Steps to reproduce the behavior:
https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-5.0&pivots=webassembly
Expected behavior
Import JS module only when component is rendered in the browser.