Component CSS Disappears from Components During App Bootsrapping With Preboot

人盡茶涼 提交于 2020-01-02 06:48:12

问题


My beautiful server-side rendered Angular 5 application (using Universal with a node express.js server) is having problems with styling during the bootstrap (preboot) phase. The global CSS stylesheet seems to be fine, but the component-specific styles disappear once bootstrapping begins.

Example:

Component styling with javascript disabled (pure html and css from the server):

Component styling with javascript enabled and before app starts bootstrapping (still fine, still pure html and css from the server):

Component styling during bootstrapping transition phase (terrible because the component specific styles are gone. h1[_ngcontent-c25] is no longer there):

Component styling after app bootstrapping is completely finished (h1[_ngcontent-c25] is back):

What is going on here and how do I fix it?

For reference

app.module.ts:

@NgModule({
declarations: [
    AppComponent,
],
imports: [
    // BrowserModule,
    BrowserModule.withServerTransition({ appId: 'universal' }),
    PrebootModule.withConfig({ appRoot: 'app-root' }),
    BrowserTransferStateModule,
    TransferHttpCacheModule,
    CoreModule, // this is where everything else is
    AppRoutingModule,
],
bootstrap: [
    AppComponent
]
})
export class AppModule { }

Versions:

Angular: 5.0.3
Angular-cli: 1.5.0
"preboot": "^6.0.0-beta.0",
"@nguniversal/module-map-ngfactory-loader": "^5.0.0-beta.5",
"@nguniversal/common": "5.0.0-beta.5",
"express": "^4.16.2",

UPDATE:

Example repo with same problem from another developer: https://github.com/angular/preboot/issues/58


回答1:


Two things solved the problem for me:

  1. Add {initialNavigation: 'enabled'} to config param of RouterModule.forRoot import.

like this:

 @NgModule({
   imports: [
     RouterModule.forRoot( routes, { initialNavigation: 'enabled' } )
   ],
   ...
  1. Upgrade to latest version of preboot (6.0.0-beta.1)


来源:https://stackoverflow.com/questions/47701349/component-css-disappears-from-components-during-app-bootsrapping-with-preboot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!