From 1ea33d83bf5bbc286625d6da802625bbfd89b05f Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Thu, 24 Sep 2020 12:51:07 -0700 Subject: [PATCH] Fix undefined error in server tree data source (#12616) * Fix undefined error in server tree data source * Add comment --- .../objectExplorer/browser/serverTreeDataSource.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/services/objectExplorer/browser/serverTreeDataSource.ts b/src/sql/workbench/services/objectExplorer/browser/serverTreeDataSource.ts index e7a4d27f1a..ebcbdb6876 100644 --- a/src/sql/workbench/services/objectExplorer/browser/serverTreeDataSource.ts +++ b/src/sql/workbench/services/objectExplorer/browser/serverTreeDataSource.ts @@ -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 || ''; } /**