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

* Fix undefined error in server tree data source

* Add comment

(cherry picked from commit 1ea33d83bf)
This commit is contained in:
Charles Gagnon
2020-09-25 13:43:47 -07:00
committed by GitHub
parent 76d7b0a9fe
commit 6de11c8107

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 || '';
}
/**