Skip to content

Lazy loading might encounter issues if host page rerenders during loading #24211

@SteveSandersonMS

Description

@SteveSandersonMS

Each time the host page rerenders (e.g., for reasons unrelated to navigation), it will call the router's SetParametersAsync, which in turn calls Refresh which then calls _renderHandle.Render(Found(routeData));. It does this even if a lazy-load is currently in progress, which means it might throw if the route relies on assemblies not yet loaded.

At minimum, we could address this by making the router a bit more stateful. It could keep track of whether a load is in progress, and if so, render the Navigating fragment if there is one, or skip rendering if not.

A more sophisticated solution might involve changing the OnNavigateAsync callback to be an EventCallback<T> and letting the event system be responsible for rerendering during navigation. This would have some benefits like auto-rendering the host page on navigation just like any other event handler. It's a bit tricky to wrap one eventcallback inside another but I think it's technically possible because we're inside the M.A.Components project and hence can freely read the internal properties of EventCallback<T>. Update: Filed #24215 to track this separate aspect of it.

Metadata

Metadata

Assignees

Labels

DoneThis issue has been fixedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-lazy-loadingIssues related to adding support for lazy-loading in Blazorfeature-blazor-wasmThis issue is related to and / or impacts Blazor WebAssembly

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions