fixed the issue by installing preboot,For the people who are having the same issue, you can follow this:
we need to wait for the full client app to bootstrap and run or buffer events using librabries like preboot.
npm i preboot
add below code under imports of app.module.ts
PrebootModule.withConfig({ appRoot: 'app-root' })
Also add the below code to your providers in app.module.ts if necessary,
{
provide: APP_INITIALIZER,
useFactory: function(document: HTMLDocument, platformId: Object): Function {
return () => {
if (isPlatformBrowser(platformId)) {
const dom = ɵgetDOM();
const styles: any[] = Array.prototype.slice.apply(dom.querySelectorAll(document, `style[ng-transition]`));
styles.forEach(el => {
// Remove ng-transition attribute to prevent Angular appInitializerFactory
// to remove server styles before preboot complete
el.removeAttribute('ng-transition');
});
document.addEventListener('PrebootComplete', () => {
// After preboot complete, remove the server scripts
setTimeout(() => styles.forEach(el => dom.remove(el)));
});
}
};
},
deps: [DOCUMENT, PLATFORM_ID],
multi: true
}
And after adding these, for me the flickering issue was resolved.
Refer the official angular ssr link for more clarity : https://angular.io/guide/universal