From 197ef39c1ae5baf8c40079adc4bca9ecd1c45e8a Mon Sep 17 00:00:00 2001 From: ttonev Date: Tue, 2 Sep 2025 18:16:15 +0300 Subject: [PATCH 1/4] fix(tree): fixed tests and removed redundant code --- .../igniteui-angular/src/lib/tree/tree-navigation.spec.ts | 4 +++- .../igniteui-angular/src/lib/tree/tree-selection.spec.ts | 4 +++- projects/igniteui-angular/src/lib/tree/tree.component.ts | 5 +++++ projects/igniteui-angular/src/lib/tree/tree.spec.ts | 5 ++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/projects/igniteui-angular/src/lib/tree/tree-navigation.spec.ts b/projects/igniteui-angular/src/lib/tree/tree-navigation.spec.ts index 47f5d551d43..8678be6600c 100644 --- a/projects/igniteui-angular/src/lib/tree/tree-navigation.spec.ts +++ b/projects/igniteui-angular/src/lib/tree/tree-navigation.spec.ts @@ -10,6 +10,7 @@ import { IgxTreeService } from './tree.service'; import { IgxTreeComponent } from './tree.component'; import { IgxTree, IgxTreeNode, IgxTreeSelectionType } from './common'; import { IgxTreeNodeComponent } from './tree-node/tree-node.component'; +import { PlatformUtil } from '../core/utils'; describe('IgxTree - Navigation #treeView', () => { @@ -780,7 +781,8 @@ describe('IgxTree - Navigation #treeView', () => { spyOn(nav, 'update_disabled_cache'); spyOn(nav, 'update_visible_cache'); spyOn(nav, 'register'); - const tree = new IgxTreeComponent(nav, mockSelectionService, mockTreeService, mockElementRef); + const mockPlatform = jasmine.createSpyObj('platform', ['isBrowser', 'isServer']); + const tree = new IgxTreeComponent(nav, mockSelectionService, mockTreeService, mockElementRef, mockPlatform); tree.nodes = mockQuery; expect(nav.register).toHaveBeenCalledWith(tree); expect(nav.init_invisible_cache).not.toHaveBeenCalled(); diff --git a/projects/igniteui-angular/src/lib/tree/tree-selection.spec.ts b/projects/igniteui-angular/src/lib/tree/tree-selection.spec.ts index c2a7b7b1f0f..6ea2db4fe0c 100644 --- a/projects/igniteui-angular/src/lib/tree/tree-selection.spec.ts +++ b/projects/igniteui-angular/src/lib/tree/tree-selection.spec.ts @@ -552,7 +552,9 @@ describe('IgxTree - Selection #treeView', () => { const selectionService = new IgxTreeSelectionService(); const treeService = new IgxTreeService(); const navService = new IgxTreeNavigationService(treeService, selectionService); - const tree = new IgxTreeComponent(navService, selectionService, treeService, null); + const mockPlatform = jasmine.createSpyObj('platform', ['isBrowser', 'isServer']); + mockPlatform.isBrowser = true; + const tree = new IgxTreeComponent(navService, selectionService, treeService, null, mockPlatform); beforeEach(() => { mockNodes = TreeTestFunctions.createNodeSpies(0, 5); diff --git a/projects/igniteui-angular/src/lib/tree/tree.component.ts b/projects/igniteui-angular/src/lib/tree/tree.component.ts index 2ee5d39e79f..444ddd3b211 100644 --- a/projects/igniteui-angular/src/lib/tree/tree.component.ts +++ b/projects/igniteui-angular/src/lib/tree/tree.component.ts @@ -504,6 +504,11 @@ export class IgxTreeComponent implements IgxTree, OnInit, AfterViewInit, OnDestr requestAnimationFrame(() => { this.selectionService.selectNodesWithNoEvent(toBeSelected); }); + if(this.platform.isBrowser) { + requestAnimationFrame(() => { + this.selectionService.selectNodesWithNoEvent(toBeSelected); + }); + } this.forceSelect = []; this.nodes.forEach(node => { node.expandedChange.pipe(takeUntil(this.unsubChildren$)).subscribe(nodeState => { diff --git a/projects/igniteui-angular/src/lib/tree/tree.spec.ts b/projects/igniteui-angular/src/lib/tree/tree.spec.ts index dea876aaaa6..069d8f1d2e4 100644 --- a/projects/igniteui-angular/src/lib/tree/tree.spec.ts +++ b/projects/igniteui-angular/src/lib/tree/tree.spec.ts @@ -11,6 +11,7 @@ import { IgxTreeNodeComponent } from './tree-node/tree-node.component'; import { IgxTreeSelectionService } from './tree-selection.service'; import { IgxTreeComponent } from './tree.component'; import { IgxTreeService } from './tree.service'; +import { PlatformUtil } from '../core/utils'; const TREE_ROOT_CLASS = 'igx-tree__root'; const NODE_TAG = 'igx-tree-node'; @@ -45,8 +46,10 @@ describe('IgxTree #treeView', () => { mockElementRef = jasmine.createSpyObj('elementRef', [], { nativeElement: document.createElement('div') }); + const mockPlatform = jasmine.createSpyObj('platform', ['isBrowser', 'isServer']); + mockPlatform.isBrowser = true; tree?.ngOnDestroy(); - tree = new IgxTreeComponent(mockNavService, mockSelectionService, mockTreeService, mockElementRef); + tree = new IgxTreeComponent(mockNavService, mockSelectionService, mockTreeService, mockElementRef, mockPlatform); mockNodes = jasmine.createSpyObj('mockList', ['toArray'], { changes: new Subject(), get first() { From 3073c964bfa0b1959134d07c4364af95116db492 Mon Sep 17 00:00:00 2001 From: tishko0 Date: Thu, 18 Sep 2025 11:55:43 +0300 Subject: [PATCH 2/4] fix(tree): added missing import and removed extra raf call --- .../igniteui-angular/src/lib/tree/tree.component.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/projects/igniteui-angular/src/lib/tree/tree.component.ts b/projects/igniteui-angular/src/lib/tree/tree.component.ts index 444ddd3b211..208dfb00801 100644 --- a/projects/igniteui-angular/src/lib/tree/tree.component.ts +++ b/projects/igniteui-angular/src/lib/tree/tree.component.ts @@ -29,7 +29,7 @@ import { IgxTreeNodeComponent } from './tree-node/tree-node.component'; import { IgxTreeSelectionService } from './tree-selection.service'; import { IgxTreeService } from './tree.service'; import { growVerIn, growVerOut } from 'igniteui-angular/animations'; -import { resizeObservable } from '../core/utils'; +import { PlatformUtil, resizeObservable } from '../core/utils'; /** * @hidden @internal @@ -327,6 +327,7 @@ export class IgxTreeComponent implements IgxTree, OnInit, AfterViewInit, OnDestr private selectionService: IgxTreeSelectionService, private treeService: IgxTreeService, private element: ElementRef, + private platform: PlatformUtil, ) { this.selectionService.register(this); this.treeService.register(this); @@ -501,14 +502,15 @@ export class IgxTreeComponent implements IgxTree, OnInit, AfterViewInit, OnDestr private subToChanges() { this.unsubChildren$.next(); const toBeSelected = [...this.forceSelect]; - requestAnimationFrame(() => { - this.selectionService.selectNodesWithNoEvent(toBeSelected); - }); + if(this.platform.isBrowser) { requestAnimationFrame(() => { this.selectionService.selectNodesWithNoEvent(toBeSelected); }); + } else { + this.selectionService.selectNodesWithNoEvent(toBeSelected); } + this.forceSelect = []; this.nodes.forEach(node => { node.expandedChange.pipe(takeUntil(this.unsubChildren$)).subscribe(nodeState => { From c3ec4f3476f10835060f4766362ab257574297db Mon Sep 17 00:00:00 2001 From: tishko0 Date: Fri, 19 Sep 2025 11:23:10 +0300 Subject: [PATCH 3/4] fix(tree): removed unnesesary else --- projects/igniteui-angular/src/lib/tree/tree.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/projects/igniteui-angular/src/lib/tree/tree.component.ts b/projects/igniteui-angular/src/lib/tree/tree.component.ts index 208dfb00801..4cdcf817962 100644 --- a/projects/igniteui-angular/src/lib/tree/tree.component.ts +++ b/projects/igniteui-angular/src/lib/tree/tree.component.ts @@ -507,8 +507,6 @@ export class IgxTreeComponent implements IgxTree, OnInit, AfterViewInit, OnDestr requestAnimationFrame(() => { this.selectionService.selectNodesWithNoEvent(toBeSelected); }); - } else { - this.selectionService.selectNodesWithNoEvent(toBeSelected); } this.forceSelect = []; From 15cc615a4f6cd6d1a14911991626ce556c240962 Mon Sep 17 00:00:00 2001 From: tishko0 Date: Fri, 19 Sep 2025 11:24:57 +0300 Subject: [PATCH 4/4] Merge branch 'ttonev/tree-fix-ssr-20.x' of https://github.com/IgniteUI/igniteui-angular into ttonev/tree-fix-ssr-20.x