I am building a razor page that contains a number of razor components that utilize Blazor Bootstrap doughnut charts and bar charts on a Blazor application. One of the elements on the page is a link to a different page on my application. When I open the page and try to click the link before all of the components have rendered, it throws the following exception:
Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'id')
TypeError: Cannot read properties of null (reading 'id')
The error message indicates this exception is thrown in the sub-components that contain the Bootstrap charts. The Bootstrap components follow the the same initialization procedure that is in their demos (https://demos.blazorbootstrap.com/charts/doughnut-chart) where I am configuring the data and options in OnInitialized() and initializing the chart in OnAfterRenderAsync(...). Here is sample code from one of the components that fail. Error indicates the exception is thrown at PreviousDonut.InitializeAsync...
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await CurrentDonut.InitializeAsync(CurrentUsageData, CurrentUsageOptions);
}
await base.OnAfterRenderAsync(firstRender);
}
And where it tries to navigate on button click...
private void Navigate()
{
string url = $"/Dashboard";
NavManager.NavigateTo(url);
}
I am trying to navigate between pages without having to wait for every component to be rendered.
I tried changing the link element from an anchor element to a button that calls NavigationManager.NavigateTo(link) with no success.
I tried setting the forceReload parameter in the NavigateTo() call which solves this problem, but resets the user authentication, so I cannot use this solution.
NavigationManager. It would help if you could post the relevant parts of your code to help others understand your issue.CurrentDonut.InitializeAsyncand calling it, but there's no option to do so. Without a deep look into their code I can't be sure, but there's probably some calls being made against disposed objects. How to solve - no idea [it's third party code]. Someone with more knowledge ofBlazor Bootstrapmay be able o provide an answer.