Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Angular Universal Common Module doesnt work with aspnetcore-engine #835

Closed
naveedahmed1 opened this issue Nov 2, 2017 · 12 comments
Closed

Comments

@naveedahmed1
Copy link

  • I'm submitting a ...
- [x ] bug report
  • What modules are related to this Issue?
- [x ] aspnetcore-engine
- [ x] common module

Since the intro page of Angular Universal Common Module says "This is the common Angular Universal module that is common across server-side rendering app irrespective of the rendering engine." I assume it should also work with aspnetcore-engine.

I tried adding it to my aap, but it seems that it doesn't work. Though it doesn't break the app as with that case mentioned in #832 , but the requests are executed twice, once on server and then again on client.

@naveedahmed1
Copy link
Author

I think the issue here is again due to ServerTransferStateModule , though the docs about Angular Universal Common Module doesn't mentioned that we are also required to import ServerTransferStateModule. But looking at the code it seems that we must import it and after you import ServerTransferStateModule, its break the app.

@MarkPieszak
Copy link
Contributor

MarkPieszak commented Nov 3, 2017

Somehow adding ServerTransferStateModule breaks the server-render completely, it's on my radar, just need some time to investigate it further.

This is the same issue as #832

@grundera
Copy link

I've investigated that ServerTransferStateModule breaks server-side rendering because it adds a hook to BEFORE_APP_SERIALIZED providers.
I've tested it by making a simple module with the BEFORE_APP_SERIALIZED provider and importing it in the same place as the ServerTransferStateModule.

The issue is related to aspnetcore-engine because it also adds a hook to BEFORE_APP_SERIALIZED in extraProviders. express-engine doesn't add a hook a it works with it.

@naveedahmed1
Copy link
Author

I think aspnetcore-engine would be deprecated soon, the new upcoming template from Microsoft, won't need it. Have a look at aspnet/JavaScriptServices#1288 (comment)

@devel112
Copy link

devel112 commented Jan 4, 2018

Possible cause

ServerTransferStateModule version 5.1.3
https://github.com/angular/angular/blob/5.1.3/packages/platform-server/src/transfer_state.ts

aspnetcore-engine version 35bfc51 on Oct 11, 2017
https://github.com/angular/universal/blob/master/modules/aspnetcore-engine/src/main.ts

ServerTransferStateModule.serializeTransferStateFactory() appends to doc.body while aspnetcore-engine only checks in doc.head for scripts.

Also maybe a possible race condition using BEFORE_APP_SERIALIZED since ServerTransferStateModule.serializeTransferStateFactory() and aspnetcore-engine's extracting of scripts uses BEFORE_APP_SERIALIZED and to get the state scipt aspnetcore-engine's needs to trigger after ServerTransferStateModule.serializeTransferStateFactory()

If a version of renderModuleFactory could return a Domino document that would make aspnetcore-engine not need to use BEFORE_APP_SERIALIZED.

I tested that state transfer works in template:
https://github.com/MarkPieszak/aspnetcore-angular2-universal/tree/angular-5.0-WIP (updated to angular 5.1.3)
using a modified version of aspnetcore-engine:
https://github.com/devel112/universal/commit/d877214825bd3f564c4ff49f775795b70d45d96a

esoderquist added a commit to esoderquist/universal that referenced this issue Jan 7, 2018
@stephenlautier
Copy link
Contributor

@devel112 I'm trying also to get this working, and pretty much almost came to you're the conclusion as well. One thing I noticed is that when registering ServerTransferStateModule the universal BEFORE_APP_SERIALIZED doesnt get registered, hence thats why it doesnt work

I still dont get exactly why when registering the ServerTransferStateModule the other doesnt work. If I register another multi: true BEFORE_APP_SERIALIZED, along with the universal internal (which both are in the extraProviders they work.

If a version of renderModuleFactory could return a Domino document that would make aspnetcore-engine not need to use BEFORE_APP_SERIALIZED.

Ideally in my opinion, instead of just the HTML it should return the moduleRef, so you can use the injector from outside

@KhalipskiSiarhei
Copy link

@stephenlautier, @devel112 Is the mentioned above modified aspnetcore-engine fixed the issue or not?

@stephenlautier
Copy link
Contributor

I haven't tried exactly the mentioned solution, but more or less it should work. Ideally, for the .net we return the state as an object instead of embedding it as script and add it to the globals

@devel112
Copy link

@MarkPieszak Proposal: Change strategy from mangling AngularCompiler output to aspnet supplying an index.html file/code that AngularCompiler weaves the app into?

@devel112
Copy link

Fixed in #889

@CaerusKaru
Copy link
Member

Please keep in mind that this won't actually be resolved until the new packages have been published, which should be imminent.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants