Skip to content

Commit ef71c18

Browse files
committed
Fixes finding view nodes if view isn't loaded yet
1 parent d6f56aa commit ef71c18

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

src/views/viewBase.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -349,26 +349,30 @@ export abstract class ViewBase<
349349
): Promise<ViewNode | undefined> {
350350
const cc = Logger.getCorrelationContext();
351351

352-
// If we have no root (e.g. never been initialized) force it so the tree will load properly
353-
if (this.root == null) {
354-
await this.show();
352+
async function find(this: ViewBase<RootNode, ViewConfig>) {
353+
try {
354+
const node = await this.findNodeCoreBFS(
355+
typeof predicate === 'string' ? n => n.id === predicate : predicate,
356+
this.ensureRoot(),
357+
allowPaging,
358+
canTraverse,
359+
maxDepth,
360+
token,
361+
);
362+
363+
return node;
364+
} catch (ex) {
365+
Logger.error(ex, cc);
366+
return undefined;
367+
}
355368
}
356369

357-
try {
358-
const node = await this.findNodeCoreBFS(
359-
typeof predicate === 'string' ? n => n.id === predicate : predicate,
360-
this.ensureRoot(),
361-
allowPaging,
362-
canTraverse,
363-
maxDepth,
364-
token,
365-
);
366-
367-
return node;
368-
} catch (ex) {
369-
Logger.error(ex, cc);
370-
return undefined;
371-
}
370+
if (this.root != null) return find.call(this);
371+
372+
// If we have no root (e.g. never been initialized) force it so the tree will load properly
373+
await this.show();
374+
// Since we have to show the view, let the callstack unwind before we try to find the node
375+
return new Promise<ViewNode | undefined>(resolve => setTimeout(() => resolve(find.call(this)), 0));
372376
}
373377

374378
private async findNodeCoreBFS(

0 commit comments

Comments
 (0)