Skip to content

Commit 8a6027d

Browse files
JeanMecheAndrewKushnir
authored andcommitted
refactor(devtools): fix issue with virtual scroll viewport in the directive forest (#54912)
In some cases the height of the viewport wasn't calculated correctly because of extension tabs quirks. This commit fixes this issue. Fixes #53704 PR Close #54912
1 parent 356ec65 commit 8a6027d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎devtools/projects/ng-devtools/src/lib/devtools-tabs/directive-explorer/directive-forest/directive-forest.component.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ChangeDetectionStrategy,
1717
ChangeDetectorRef,
1818
Component,
19+
ElementRef,
1920
EventEmitter,
2021
HostListener,
2122
Input,
@@ -99,11 +100,13 @@ export class DirectiveForestComponent {
99100
readonly itemHeight = 18;
100101

101102
private _initialized = false;
103+
private resizeObserver: ResizeObserver;
102104

103105
constructor(
104106
private _tabUpdate: TabUpdate,
105107
private _messageBus: MessageBus<Events>,
106108
private _cdr: ChangeDetectorRef,
109+
private elementRef: ElementRef,
107110
) {
108111
this.subscribeToInspectorEvents();
109112
this._tabUpdate.tabUpdate$.pipe(takeUntilDestroyed()).subscribe(() => {
@@ -114,6 +117,17 @@ export class DirectiveForestComponent {
114117
});
115118
}
116119
});
120+
121+
// In some cases there a height changes, we need to recalculate the viewport size.
122+
this.resizeObserver = new ResizeObserver(() => {
123+
this.viewport.scrollToIndex(0);
124+
this.viewport.checkViewportSize();
125+
});
126+
this.resizeObserver.observe(this.elementRef.nativeElement);
127+
}
128+
129+
ngOnDestroy(): void {
130+
this.resizeObserver.disconnect();
117131
}
118132

119133
subscribeToInspectorEvents(): void {

0 commit comments

Comments
 (0)