When you change the data source of the treeview and the new data has a different set of Expanded states than the old data, you will get a `Microsoft.JSInterop.JSException: 'Cannot read property 'scrollHeight' of null` in VS. It will also fail to show you proper debug information, symbols and source code.
Simple Repro
@
using
Telerik.Blazor.Components.TreeView
<button
class
=
"btn btn-primary"
@onclick=
"@(() => ChangeTreeData(false))"
>Change tree data</button>
<TelerikTreeView Data=
"@FlatData"
>
<TelerikTreeViewBindings>
<TelerikTreeViewBinding ParentIdField=
"Parent"
ExpandedField=
"IsExpanded"
></TelerikTreeViewBinding>
</TelerikTreeViewBindings>
</TelerikTreeView>
@code {
public
List<TreeItem> FlatData {
get
;
set
; } =
new
List<TreeItem>();
public
class
TreeItem
//most fields use the default names and will bind automatically in this example
{
public
int
Id {
get
;
set
; }
public
string
Text {
get
;
set
; }
public
int
? Parent {
get
;
set
; }
//this is a non-default field name
public
bool
HasChildren {
get
;
set
; }
public
bool
IsExpanded {
get
;
set
; }
//this is a non-default field name
}
protected
override
void
OnInit()
{
ChangeTreeData(
true
);
}
int
currIndex {
get
;
set
; } = 0;
void
ChangeTreeData(
bool
expandItems)
{
currIndex++;
FlatData.Clear();
List<TreeItem> data =
new
List<TreeItem>();
data.Add(
new
TreeItem { Id = currIndex, HasChildren =
true
, IsExpanded = expandItems, Parent =
null
, Text = $
"root {currIndex}"
});
data.Add(
new
TreeItem { Id = currIndex + 1, HasChildren =
false
, IsExpanded = expandItems, Parent = currIndex, Text = $
"root {currIndex}: child one"
});
FlatData.AddRange(data);
}
}