-
Notifications
You must be signed in to change notification settings - Fork 12
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
Doesn't work with prerendering #27
Comments
Hey thanks for raising.. Is this coming from the We do this here: BlazorIntersectionObserver/src/Blazor.IntersectionObserver/IntersectionObserve.cs Line 37 in 6c69abe
We also have it as a task for invocation: BlazorIntersectionObserver/src/Blazor.IntersectionObserver/IntersectionObserverService.cs Line 27 in 6c69abe
|
Hello, I've looked at this more closely and in my case it's the @inject IIntersectionObserverService ObserverService So what I did instead was to inject 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.
The text was updated successfully, but these errors were encountered: