Skip to content

refactor(tree): add raf check for tree SSR #16102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 20.0.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions projects/igniteui-angular/src/lib/tree/tree.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -327,6 +327,7 @@ export class IgxTreeComponent implements IgxTree, OnInit, AfterViewInit, OnDestr
private selectionService: IgxTreeSelectionService,
private treeService: IgxTreeService,
private element: ElementRef<HTMLElement>,
private platform: PlatformUtil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some failing tests due to the constructor changes. Those should be fixed.

) {
this.selectionService.register(this);
this.treeService.register(this);
Expand Down Expand Up @@ -501,9 +502,13 @@ export class IgxTreeComponent implements IgxTree, OnInit, AfterViewInit, OnDestr
private subToChanges() {
this.unsubChildren$.next();
const toBeSelected = [...this.forceSelect];
requestAnimationFrame(() => {
if(this.platform.isBrowser) {
requestAnimationFrame(() => {
this.selectionService.selectNodesWithNoEvent(toBeSelected);
});
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed to set the selection on the server? I assume that when the view hydrates it would go through the same logic and apply selection if needed, so maybe the else handling here is redundant.

this.selectionService.selectNodesWithNoEvent(toBeSelected);
});
}
this.forceSelect = [];
this.nodes.forEach(node => {
node.expandedChange.pipe(takeUntil(this.unsubChildren$)).subscribe(nodeState => {
Expand Down
Loading