Aspnetcore-angular-universal: State Rehydration with TransferState

Created on 5 Feb 2018  路  8Comments  路  Source: TrilonIO/aspnetcore-angular-universal

Since we upgraded to the latest version of this repo our state rehydration fails.

Found this in app.module.server

// HttpTransferCacheModule still needs fixes for 5.0
    //   Leave this commented out for now, as it breaks Server-renders
    //   Looking into fixes for this! - @MarkPieszak
    //ServerTransferStateModule

Any ideas when this will be fixed? Can you @MarkPieszak point me in the right direction and then I can investigate as well.

Most helpful comment

@stephenlautier You rock!
Let me talk to the team and see if we can push in those changes asap so we can publish a new version of the engine etc out!

All 8 comments

I'm trying to look into this as well, any help would be appreciated.

What i've discovered so far:

  • when adding ServerTransferStateModule - no html is outputted, i was debugging to understand why its returning "" , what i've noticed is that within angular https://github.com/angular/angular/blob/master/packages/platform-server/src/utils.ts#L63 its actually outputted.
  • I was experimenting to add my own service (or register TransferState) alone, however the moduleRef is not exposed if it was i could fix it. As i managed to hack it however without using the new module renderModuleFactory and @nguniversal/aspnetcore-engine (which im not happy to do)

update: what i noticed is when registering ServerTransferStateModule the universal beforeAppSerialized is not being triggered.. cant understand why because both uses multi: true

update#2

So pretty much I have a working solution and got it working on our project, but it requires some changes, ideally in both angular and universal

  • Submitted an issue on angular https://github.com/angular/angular/issues/22049 - its a very simple change but its breaking, not sure if they agree to do so
  • Requires some changes in universal aspnetcore-engine tomorrow I will try to submit a PR to it, and move the breaking change temp in it gets accepted TransferState will work for aspnet 馃巻

@stephenlautier You rock!
Let me talk to the team and see if we can push in those changes asap so we can publish a new version of the engine etc out!

@MarkPieszak Any updates?

A new update has been released (in angular/universal repo) about a week or so ago, can you give it a shot and let us know if it's working? @Flood

It seems to work! State rehydration works on my project but SSR does not. It breaks on

ERROR ReferenceError: Event is not defined (see https://github.com/angular/universal/issues/844)

However, SSR works on this repo. I guess it will work on my project when the Event issue is solved.

Excellent 馃憤
That might be coming from a third party library you have (?)

Just add global['Event'] = null; to your boot.server.ts file, and that should help the issue.

A lot of times you need to mock/stub things in Node to handle crazy global (typically browser-only items). Unfortunately a lot of people forget you should always check for the existence of global variables :(

Closing as TransferState works now 馃拑

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterdobson picture peterdobson  路  4Comments

digibum picture digibum  路  4Comments

MapleYe picture MapleYe  路  3Comments

odahcam picture odahcam  路  4Comments

AbrarJahin picture AbrarJahin  路  4Comments