I'm trying to find why my code is binding root two times using Angular 9 SSR.
I tried eventReplayer.replayAll() trick but I'm still stuck, I noticed when I'm scrolling into the page finally I'm getting the the proper root loaded perfectly and the other one removed (ng-non-bindable), so I removed PrebootModule just to narrow the issue and I got one root in my dom but the application won't run properly.
app.component.ts
BrowserModule.withServerTransition({appId: 'dcaa'}),
PrebootModule.withConfig({appRoot: 'dcaa-root'}),
.
.
.
{
provide: APP_INITIALIZER,
useFactory: function (document: HTMLDocument, platformId: Object): Function {
return () => {
if (isPlatformBrowser(platformId)) {
const dom = getDOM();
const styles: any[] = Array.prototype.slice.apply(document.querySelectorAll('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
}
app.routes.ts
imports: [RouterModule.forRoot(routes, {
scrollPositionRestoration: 'disabled',
relativeLinkResolution: 'corrected',
preloadingStrategy: PreloadAllModules,
initialNavigation: 'enabled'
}),
app.server.module.ts
imports: [
AppModule,
ServerModule,
ServerTransferStateModule,
FlexLayoutServerModule
],
main.ts
document.addEventListener('DOMContentLoaded', () => {
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch(err => console.log(err));
});
