Skip to content

Commit d97acd1

Browse files
authored
fix(button): button suffering from FOUC in certain cases (#16402)
1 parent c32d22e commit d97acd1

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

projects/igniteui-angular/src/lib/directives/button/button-base.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Output,
99
booleanAttribute,
1010
inject,
11-
afterRenderEffect,
11+
AfterViewInit,
1212
} from '@angular/core';
1313
import { PlatformUtil } from '../../core/utils';
1414

@@ -20,8 +20,9 @@ export const IgxBaseButtonType = {
2020

2121

2222
@Directive()
23-
export abstract class IgxButtonBaseDirective {
23+
export abstract class IgxButtonBaseDirective implements AfterViewInit{
2424
private _platformUtil = inject(PlatformUtil);
25+
private _viewInit = false;
2526

2627
/**
2728
* Emitted when the button is clicked.
@@ -101,15 +102,16 @@ export abstract class IgxButtonBaseDirective {
101102
// In SSR there is no paint, so there’s no visual rendering or transitions to suppress.
102103
// Fix style flickering https://github.com/IgniteUI/igniteui-angular/issues/14759
103104
if (this._platformUtil.isBrowser) {
104-
afterRenderEffect({
105-
write: () => {
106-
this.element.nativeElement.style.setProperty('--_init-transition', '0s');
107-
},
108-
read: () => {
109-
requestAnimationFrame(() => {
110-
this.element.nativeElement.style.removeProperty('--_init-transition');
111-
});
112-
}
105+
this.element.nativeElement.style.setProperty('--_init-transition', '0s');
106+
}
107+
}
108+
109+
public ngAfterViewInit(): void {
110+
if (this._platformUtil.isBrowser && !this._viewInit) {
111+
this._viewInit = true;
112+
113+
requestAnimationFrame(() => {
114+
this.element.nativeElement.style.removeProperty('--_init-transition');
113115
});
114116
}
115117
}

0 commit comments

Comments
 (0)