Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Styles approach in ngAspnetCoreEngine #424

Closed
naveedahmed1 opened this issue Sep 26, 2017 · 2 comments
Closed

Issues with Styles approach in ngAspnetCoreEngine #424

naveedahmed1 opened this issue Sep 26, 2017 · 2 comments

Comments

@naveedahmed1
Copy link

naveedahmed1 commented Sep 26, 2017

I am using Angular 4.4.3, and angular/material 2.0.0-beta.11 and ngAspnetCoreEngine form this repository in one of my projects. There is a slight difference the way I am setting title and canonical tags in my app. Since majority of the pages in my case are dynamic and both title and canonical tags are dynamic as well. Therefore instead of setting title and links from App component on (router change subscription) I set title and links from the component corresponding to the page. For title I am using Title service from Angular and for Links I am using Links server from this repo.

Today when I inspected the generated markup of few pages of my app. I found duplicate title and canonical tags.

I did some research and found that the issue is due to the way ngAspnetCoreEngine fetches the styles:

let STYLES_STRING: string = htmlDoc.indexOf('<style ng-transition') > -1
                                    ? htmlDoc.substring(
                                        htmlDoc.indexOf('<style ng-transition'),
                                        htmlDoc.lastIndexOf('</style>') + 8)
                                    : null;

Since I am using Material it appends several style tags to the Head element, each tag containing styles related to specific component or group of components. Now when I add Title from my component its not always the first element after <head> tag. Sometimes its after few styles tags, followed by few other style tags.

Although using the above approach, selects all style tags but it also select the title and meta tags if they fall in between style tags. As a result the final markup which is sent from the server to the browser contains multiple Title tags. One form globals.title and other from the globals.styles.

There is some code in ngAspnetCoreEngine, but its commented

// Broken after 4.0 (worked in rc)
                  // if (element.name === 'style') {
                  //   let styleTag = '<style ';
                  //   for (let key in element.attribs) {
                  //     if (key) {
                  //       styleTag += `${key}="${element.attribs[key]}">`;
                  //     }
                  //   }

                  //   styleTag += `${element.children[0].data}</style>`;
                  //   STYLES.push(styleTag);
                  // }

I uncommented the above code in ngAspnetCoreEngine and updated the resolve statement to the following:

resolve({
                  html: APP_HTML,
                  globals: {
                      styles: STYLES.join(' '),
                    title: TITLE,
                    scripts: SCRIPTS.join(' '),
                    meta: META.join(' '),
                    links: LINKS.join(' ')
                  }
                });

And it started working perfectly.

Based on above, I think the styles approach in current ngAspnetCoreEngine requires an update. There is a comment in above code which says // Broken after 4.0 (worked in rc) I am not sure what exactly is broken, its working perfectly fine with Angular 4.4.3.

@MarkPieszak
Copy link
Member

It'll be adding in the upcoming 5.0 release (as it's waiting to be merged in there, there were many updates for 5.0)

5.0 PR here:
#437

Universal aspnetcore-engine PR here:
angular/universal#825

@naveedahmed1
Copy link
Author

That's great! Any update on migrating this repo to Angular 5, since Angular 5 is now in RC.

MarkPieszak added a commit that referenced this issue Nov 2, 2017
* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes #434
Closes #435
Closes #430
Closes #424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue Jan 17, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue May 15, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue May 15, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to Hunter-Industries/aspnetcore-angular2-universal that referenced this issue May 16, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue Jun 8, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue Jun 8, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue Jun 8, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
BillSheldon-HunterIndustries pushed a commit to BillSheldon-HunterIndustries/aspnetcore-angular2-universal that referenced this issue Jun 8, 2018
…IO#437)

* feat(5.0): update engine-etc for angular 5.0-rc1

WIP - More updates to come

* remove ng 4 references

* update source maps for faster HMR builds

* use aspnetcore-engine & misc updates and fixes

* update to 5.0 official

Closes TrilonIO#434
Closes TrilonIO#435
Closes TrilonIO#430
Closes TrilonIO#424
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants