-
Notifications
You must be signed in to change notification settings - Fork 12k
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
First page is loaded twice in universal app #7477
Comments
The server renders the page without any state and outputs static HTML to view in the browser while the angular application is being bootstrapped. A re-render when the application has been bootstrapped is required to use state saved in the browser such as logged in user information. |
@grizzm0 So you are saying it is a required operation. Then is there a way in which we can prevent the flicker and to make the user's experience better? |
Yes, it's required. The initial page contains static HTML which needs to be replaced with your angular application once bootstrapped. I haven't tried out universal myself yet so I don't know how bad the flicker is. Anyhow, this isn't really an issue with AngularCLI but with @angular/universal. Try searching at https://github.com/angular/angular/issues to see if anyone else has reported similar issues. |
I'm also experiencing a pretty bad flicker when angular bootstraps in the browser. @sravikiran Have you found an answer somewhere else ? |
This issue is solved in Angular 5 release. Angular 5 has State Transfer API, that allows to send the data retrieved on server to the browser. You can read about it in the following links: https://blog.angular.io/version-5-0-0-of-angular-now-available-37e414935ced and www.dotnetcurry.com/angularjs/1388/server-side-rendering-angular-nodejs |
@sravikiran Thanks for that great tutorial! For all those looking at this issue to figure out how to fix the flickering issue, I believe this is the relevant part of the article:
|
I have the same problem. I used asp.net core at first and then upgrade my application to angular 5 and know using angular universal. but the problem still exist. and I think google dose not render my page correctly. because when I checked my page with google console it didn't show my page correctly. I also changed all my http to new httpClient but the problem still exist |
same problem here with angular 5.2 |
1 similar comment
same problem here with angular 5.2 |
That code given above by @jfahrenkrug is sometimes bugging. For example I had a problem with home page, I couldn't see view-source. Anyway, did you get any solution for that blinking ? |
@sravikiran Thanks for the great tutorial! In pokemon.service.ts :
Not sure if it is a good idea to do what I did. Appreciate if anyone can point out improvements / possible mistakes in my suggestion. :) @patrykp57 the guide works well. The page blinking/flickering has stopped for me. I implemented the guide on my own site with slight modifications as seen above. |
@gimox and @HuddleHouse did you manage to solve this issue for Angular 5.2? I am facing the same problem. Please, give me the solution if you have one. |
same here |
same problem here with angular 5.2 |
I have similar problem with this issue in Angular 5.2.4. I have tried to add |
I managed to solve the double request problem (the main reason as to why the page flickers or blinks) similar to @EdwinChua 's solution, but with a HttpInterceptor between service and the backend API. This module should help - TransferHttpCacheModule It has a HttpInteceptor that basically does something like @EdwinChua's solution. I modified it a bit check for This basically solved the flicker on Angular 5.2 |
@nishadmenezes problem is still here!.
it' like the browser render a not processed html page first and after a 0.500 ms get the real page from server. The only think i can do now is to add a preloading full screen page that hide after all data received in browser. |
sometimes its because of your routing. check for your routing that may be you redirect the first page to another component or module. |
I have same issue |
read this post--> angular/universal-starter#436 |
@adheegm I've tried that solution but still it's not working. You can check described issue here angular/angular#23427 |
finally I found the solution that worked. |
using angular 6.0.4, even with the state transfer, the flickering will be still there:
|
@nghenglim Have you implemented Angular 6 + Angular Universal + transfer state? I have some issues including transfer state to my code. Can you please help? |
The following link is a complete tutorial. I implement that and thank god it is OK now. I did it for angular 6+ |
yes my new blog is using angular universal and transfer state. The result is better than not using it, but flickering will be still there. flickering-universal. make service worker update on reload and use slow 3g network and disable cache. You can see the flickering. |
@nghenglim That looks great! Can you provide the steps to implement the same? |
@hinalshah91 Still enhancing the app, and it currently has a bad first meaningful paint time which is near 3000ms in my browser. Thinking it could be due to the flickering from angular which makes the time to first paint actually a bit later |
I spend two days to find solution and still have no idea. I also couldn't find any working example (try all linked above). For me SSR is completely unuseful in this situation, I can't deploy "flickering" app on my server. Could you provide any, even super simple example of app, which I run on local server and which will work without html replacing? For now Im not even sure that my problem is possible to resolve. But it looks exactly the same as in @nghenglim blog example. I work on complex app but for a sake of resolve that problem I create simple app: https://bitbucket.org/7furik7/angular-universal-test/src/master/ |
@pawelfurman seems like it mainly serve for SEO purpose. However it will be awesome if the flickering can be solved. For simplicity I also created a gif to explain the flickering with the implementation of transfer state. |
Seems like I found that my flickering is due to lazy-module. Seems like it is fixed by using
which is mentioned in angular/angular#15716 |
you can see my implementation with angular universal 6 and state worker. |
when working with angular this problem sometimes happens. especially when you ram is full. I had more problem with ram. my ram would become full and sometimes my cpu usage. but this problem is exist in development not in production. when I have this problem I usually close all other applications. |
I am having this same issue. What is the solution for this? I dont want my DOM to render again in client since it rendered at server side. Flickering is happening. We have to check condition like “not equals Browser” for our code? |
the solution is using state worker. you can check the following link: |
@hesampour, the above medium.com link also works with angular 6? |
yes. you can see my implementation in https://biomaze.org |
I am using angular 6 + universal. First page is reloading twice. Can anybody help resolve this issue?Following is my angular.json file:
My package.json file:
My webpack.server.config.js
|
you are using http request in your page. HTTP request fetching data happens twice, one time on the server and one time on the browser. so for this one not happen you should use angular madule transfer state. so at first import ServerModule, ServerTransferStateModule in your AppServerModule . and import BrowserTransferStateModule in your app madule. then every where in your code that you have used http request you should make a state key as the following: ` const DOGS_KEY = makeStateKey('dogs'); @component({ title = 'app'; dogs: any; constructor( ngOnInit() {
} |
@hesampour Have you also used prerender? |
yes |
The transfer state works now. However, we have one api which returns different response for different slug parameter we pass. So, if I use transfer state for that Api call with one slug parameter on one page and transfer state for same api call with different slug parameter on another page, it returns the previous response. Any solution for this? |
I have been searching for a proper solution for this issue. Seems like Transfer-State is the solution. But in my case I have used Lazy Loading on Angular too. So the issue persists. I managed to fix it by using,
Try this with your project. It will resolve your flickering or reloading twice issue. |
using |
@sirajtahra using |
Hey guys, // this.transferState.remove(key); // commented out |
In my case the issue was i had similar routes i.e for HomeComponent i was using '' and for ItemComponent i was using ':id/:category' so i had to change my ItemComponent to use 'item/:id/:category' as below:
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)bug report
Versions.
λ ng --version
@angular/cli: 1.3.0
node: 6.11.0
os: win32 x64
@angular/animations: 4.3.4
@angular/common: 4.3.4
@angular/compiler: 4.3.4
@angular/core: 4.3.4
@angular/forms: 4.3.4
@angular/http: 4.3.4
@angular/platform-browser: 4.3.4
@angular/platform-browser-dynamic: 4.3.4
@angular/router: 4.3.4
@angular/cli: 1.3.0
@angular/compiler-cli: 4.3.4
@angular/language-service: 4.3.4
@angular/platform-server: 4.3.4
λ node --version
v6.11.0
λ npm --version
v3.9.3
Running on Windows 10
Repro steps.
I built a sample repo using angular-cli and followed the steps in the Universal Rendering story to enable server side rendering. The application loads well on running, but I see the client rendering also happening after the page is served from the server. So the page gets rendered from the server and then the content disappears for a second as the client rendering happens.
To reproduce this, you can clone this repository, install the packages and run the following commands:
I am using the
dist/index.html
file instead ofsrc/index.html
, as on using the file from thesrc
causes full page reload when I switch between the routes.The log given by the failure.
No log, as there are no errors from npm and angular-cli
Desired functionality.
Client rendering shouldn't happen after the page is loaded from the server
The text was updated successfully, but these errors were encountered: