Fix undefined error in server tree data source (#12616)

* Fix undefined error in server tree data source

* Add comment
This commit is contained in:
Charles Gagnon
2020-09-24 12:51:07 -07:00
committed by GitHub
parent 23e1141484
commit 1ea33d83bf

View File

@@ -29,8 +29,13 @@ export class ServerTreeDataSource implements IDataSource {
* Returns the unique identifier of the given element.
* No more than one element may use a given identifier.
*/
public getId(tree: ITree, element: any): string {
return element.id;
public getId(tree: ITree, element?: any): string {
// Note there really shouldn't be any undefined elements in the tree, but the original implementation
// didn't do that correctly and since this is going to replaced by the async tree at some point just
// making it so we handle the undefined case here.
// This should be safe to do since the undefined element is only used when we want to clear the tree
// so it'll be the only "element" in the tree and thus there shouldn't be any duplicate ids
return element?.id || '';
}
/**