This is a migrated thread and some comments may be shown as answers.

Issue with Dispose and TreeView

0 Answers 41 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Johan
Top achievements
Rank 1
Johan asked on 20 Apr 2021, 12:44 PM

Hi,

We are using among other components the TreeView component for showing an hierarchical view of an organization and that works fine in most cases, there is however an issue that happens when the users are quick to navigate between views and we get an error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot read property 'addEventListener' of null
      TypeError: Cannot read property 'addEventListener' of null

After some investigation of the code and how the TreeView works we can see that this probably happens due to that the OnAfterRenderAsync of the TreeView runs InitTreeView which calls JSInterop to set event handling for example:

this.element.addEventListener(h, this.onKeyDown),
this.element.addEventListener(f, this.onMouseDown),
this.options.draggable && this.createDraggable()

but since this is run in OnAfterRenderAsync it may happen even after the component is disposed and removed from the DOM so the elements are no longer available and the error occurs.

Is this a known issue and is there a way to handle it?

Best regards

Johan

Marin Bratanov
Telerik team
commented on 20 Apr 2021, 02:57 PM

Hi Johan,

Could you check if the scenario and issue described here are what you are having: https://feedback.telerik.com/blazor/1466134-navigating-and-disposing-a-treeview-throws-errors-in-a-webassembly-app-unknown-edit-type-0

If not, how is the treeview related to the navigation, and when is the error thrown?

Also, does this happen with the latest version (2.23.0 at the time of writing)?

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Johan
Top achievements
Rank 1
commented on 20 Apr 2021, 03:13 PM

Hi Marin,

Thank you for the quick answer! We don't get the same error as in the mentioned issue (unknown-edit-type-0), our treeview is used in a component which is used in a page and the only relation to navigation is that when a user navigates the page gets disposed along with the components in it. We are using the latest version, 2.23.0.

The error is thrown after a navigation has happened and the component is disposed, but since the OnAfterRenderAsync already has been called and not completed the error is thrown when the TreeView tries to bind the events to an html-element that no longer exists. The issue only happens if the user don't wait until the page is fully rendered before they click on another page/view but since that can happen quite often this issue is causing problems.

Best regards

Johan

Marin Bratanov
Telerik team
commented on 20 Apr 2021, 04:02 PM

Hi Johan,

Can you send me a sample that shows the error you get? That scenario (a  treeview being disposed during navigation) cases the error described in the Feedback Portal page I linked.

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Johan
Top achievements
Rank 1
commented on 27 Apr 2021, 07:51 AM

Hi Marin,

Unfortunately I don't have the time at the moment to create a sample project for the issue, we have decided to not use the treeview at the moment since it doesn't work but I will get back to this issue when I have the time to create a viable solution that shows the problem.

Best regards
Johan

Marin Bratanov
Telerik team
commented on 27 Apr 2021, 04:56 PM

Hi Johan,

If you do manage to create a reproducible sample, please send it over. Without being able to reliably reproduce a bug, I could only guess and that's not very efficient.

Best regards,
Marin

No answers yet. Maybe you can help?

Tags
TreeView
Asked by
Johan
Top achievements
Rank 1
Share this question
or