From 0f345afee9a93b53b8c4f5c3b89b6be59457b4b6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 10:54:27 +0000 Subject: [PATCH 1/2] Initial plan From 259f74b513a116a2257c943698aad6d8c60c3568 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Dec 2025 11:01:05 +0000 Subject: [PATCH 2/2] Add null check to clearHighlight() and test for early destruction Co-authored-by: gedinakova <16817847+gedinakova@users.noreply.github.com> --- .../text-highlight/text-highlight.directive.spec.ts | 9 +++++++++ .../text-highlight/text-highlight.directive.ts | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.spec.ts b/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.spec.ts index 98e10d64095..32c0e855f0b 100644 --- a/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.spec.ts +++ b/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.spec.ts @@ -308,6 +308,15 @@ describe('IgxHighlight', () => { expect(() => component.highlight.activateIfNecessary()).not.toThrowError(); }); + + it('Should not throw error when destroyed before ngAfterViewInit completes', () => { + // Create the component but do NOT call detectChanges() + // This simulates the directive being destroyed before ngAfterViewInit is called + const fix = TestBed.createComponent(HighlightLoremIpsumComponent); + + // Destroy the component without initializing it + expect(() => fix.destroy()).not.toThrowError(); + }); }); @Component({ diff --git a/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.ts b/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.ts index d1c8f7d226b..23f5b7bc6d7 100644 --- a/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.ts +++ b/projects/igniteui-angular/directives/src/directives/text-highlight/text-highlight.directive.ts @@ -302,8 +302,10 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke public clearHighlight(): void { this.clearChildElements(false); - this._lastSearchInfo.searchText = ''; - this._lastSearchInfo.matchCount = 0; + if (this._lastSearchInfo) { + this._lastSearchInfo.searchText = ''; + this._lastSearchInfo.matchCount = 0; + } } /**