Skip to content

Commit 3b35c4e

Browse files
arturovtdevversion
authored andcommitted
fix(docs-infra): allow tutorial component to be GCed (angular#58028)
This commit updates the tutorial component's functionality to unsubscribe from the route data observable and stop monitoring the resizer element when the component is destroyed. This is necessary because `monitor` adds event listeners that prevent the element and component from being garbage collected. PR Close angular#58028
1 parent 057cf7f commit 3b35c4e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

adev/src/app/features/tutorial/split-resizer-handler.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {DOCUMENT} from '@angular/common';
1111
import {DestroyRef, ElementRef, Injectable, inject, signal} from '@angular/core';
1212
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
1313
import {fromEvent, combineLatest} from 'rxjs';
14-
import {map, filter} from 'rxjs/operators';
14+
import {map, filter, finalize} from 'rxjs/operators';
1515

1616
interface ResizingData {
1717
isProgress: boolean;
@@ -148,6 +148,7 @@ export class SplitResizerHandler {
148148
!!origin && (keyEvent.key === 'ArrowLeft' || keyEvent.key === 'ArrowRight'),
149149
),
150150
takeUntilDestroyed(this.destroyRef),
151+
finalize(() => this.focusMonitor.stopMonitoring(this.resizer)),
151152
)
152153
.subscribe(([_, keyEvent]) => {
153154
const shift = keyEvent.key === 'ArrowLeft' ? -1 : 1;

adev/src/app/features/tutorial/tutorial.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
Type,
2323
ViewChild,
2424
} from '@angular/core';
25+
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
2526
import {
2627
ClickOutside,
2728
DocContent,
@@ -110,6 +111,7 @@ export default class Tutorial implements AfterViewInit {
110111
filter(() =>
111112
Boolean(this.route?.routeConfig?.path?.startsWith(`${PagePrefix.TUTORIALS}/`)),
112113
),
114+
takeUntilDestroyed(),
113115
)
114116
.subscribe((data) => {
115117
const docContent = (data['docContent'] as DocContent | undefined)?.contents ?? null;

0 commit comments

Comments
 (0)