-
Notifications
You must be signed in to change notification settings - Fork 681
Re-rendering when bootstraping at client #139
Comments
I'm having the same issue here. I believe that there should exist a strategy that allows us to configure what is going to run or re-run at the client or not. For instance, if the client has a cart-id cookie, I'd like to re-run a http call to get its cart json and update the view, without bootstraping the whole app at the client. |
The flicker is something we can look at, there might be something new going on that's causing it. As for the client bootstrapping, it actually needs to render again, since that's how the browser turns it into an actual SPA application, otherwise it's nothing more than rendered html. An ideal way to store http calls from the server and use that cached data is still in the works. Is that what you guys mean? |
flickering duration increases as ajax calls on page increases |
duplicate #102 |
@gdi2290 @jeffwhelpley @MarkPieszak |
We did resolve this issue with the latest updates. The only reason why you would still see this is if @kuldeepkeshwar, is your code public? Alternatively ping me on g chat tomorrow and I can screen share with you. |
@jeffwhelpley got your point(I didn't use Ideally, if Code:
|
the latest version has preboot via flag in the express config and the client universal module checks for preboot so don't use |
@jeffwhelpley @gdi2290 repo: https://github.com/kuldeepkeshwar/universal-starter |
OK, I will try out your code tonight and let you know. |
@kuldeepkeshwar not sure if I am doing this the right way, but I just ran your project and I didn't see any flicker. Can you tell me the exact steps to take to recreate the issue (assume that i have the project running and am on the default page of the app). |
@jeffwhelpley use localhost:3000/offers/delhi-ncr or navigate to |
@kuldeepkeshwar I need to investigate this a bit further, but I don't think this has anything to do with preboot. It looks like the flash specifically is coming from the snippet behind your router outlet. I need to see why there is the delay in resolving that route because it should resolve immediately on the client, but if you look at the network tab, you can see that the client side route doesn't resolve right away. |
@jeffwhelpley API call does take time (intentionally made it wait for 1 second to make it look like more real time), but preboot should show server rendered view until client bootstraps completely |
Wait..why are you doing the http call in the provider? I am not sure that will work that way. If you move it to the ngOnInit() I would guess this problem will go away. |
@jeffwhelpley I have to put the http call in the |
Hi! I'm having the same Issue. Live Example of my problem: |
Hi, Bests, |
@jeffwhelpley you think this is a preboot issue or just a universal browser platform bootstrap issue that's causing this? We can always do some CSS trick and overlay the client boo trapped version hidden yet on top of the server rendered, then hide the server one and show the other real fast, that might work? Forget what it's doing now. |
is this what preboot does(apart from capturing the event and replaying them) ? |
There should not be any flicker. This is a bug. I will be investigating this later today and give more details about the root cause. |
@jeffwhelpley you can use this repo. |
OK, so I think we identified the root cause here. Basically, preboot.complete() is running on the client side before all the http calls complete. So, what is happening is:
That is the momentary flash that you all see. There are two ways to fix this. First, we can delay Patrick is working on the NgCache solution now, but just note that this will not be perfect for all use cases since it requires stuffing data in the server view (i.e. and thus if the data is huge it could increase the time to download the server view). So, the workaround for right now is to change AUTO_PREBOOT to false in your providers (i.e. so preboot complete() is not called automatically): and then manually call We will update this issue once there is progress either for NgCache or for something to make it easier to control preboot complete(). |
Hi @jeffwhelpley. If I simply delay the preboot by 10 seconds (just to make sure all my requests will be completed), it will blink anyway in the following scenario: angular/universal#514 (comment) |
@jeffwhelpley I guess We need to bump the version |
Ah, yes. Our mistake. Patrick is about to push in another change and he will publish the new version after that goes in. |
Hi @jeffwhelpley, quick question. I'm following your suggestion regarding AUTO_PREBOOT false and manually call the prebootComplete, but I think I'm having some rookie mistake because I'm receiving this exception:
Version: 2.1.0-rc.1 What I did is:
|
Try this:
|
Thanks @jeffwhelpley, actually it did not work:
but a similar approach does:
One naive question. Why not to put the preboot.complete() at the end of the async queue by default ?, this will force all the async events to happen before the preboot gets executed and no need to disable it and do it manually, or am I missing something ? |
Which async queue are you referring to? You can initiate async events anywhere in your code. You either need to manually coordinate them all through a custom mechanism (in which case you would have to manually call |
Well I was thinking on using the zone as you mentioned. If I got it correctly you can catch all the async calls (with the addAsyncListener I guess) on the client inside the zone (as you did on the server) and executing the preboot.complete() after all of them finish, and before the new async events from the client starts. I mean, it is like prebooting after all the "pre-render" async events got executed, but I might be missing something fundamental :) |
No, the "stable" state on the server and client are fundamentally different. They are similar but generally speaking the client "stable" state can take longer because there may be multiple async calls and push based realtime which is involved. On the server, the rule we have is just 1 iteration of async before we return the response. The client "stable" state is more complicated. But it is certainly possible and something we will explore in the future. All that said, yes, I suggest you try out your own zone implementation and play with it. If you get it working well, you should think about submitting a PR. |
Thanks for the answer, let me adjust also the way to manually execute the preboot (the previous was actually never executing :)).
And some kind of flag to not execute preboot again if the component is re-initialized. In the server will be undefined, and in the client will be defined (that was actually the original problem that I had "TypeError: angular2_universal_1.prebootComplete is not a function" |
so...as long as you have the preboot client in your client side package (which should be the case if you are including universal), then there should be a global |
Exactly, the protection is for the server, because prebootComplete is not defined in the server (I think that was the reason for the "TypeError: angular2_universal_1.prebootComplete is not a function" that I received originally, I didn't recall it was when the component is rendered on the server). |
Yes, preboot on the server is only used to insert the inline JavaScript into the page. You never call complete on the server side. |
Here's an example of how to transfer a request made on the server to the client to prime the client cache |
@gdi2290 Well done! This saved my weekend. Thanks bro! |
I added the cache to the repo |
Any update on flickering issue? The flickering persist... |
Same for me :( |
@J4cku @Skillnter there are two strategies to eliminate flickering now:
Also note that the universal team is looking into what it would take to hydrate the client app instead of re-rendering. This is not a straightforward process and lots of hurdles to overcome, but is a potential for the future. |
@jeffwhelpley update for angular 5 is in universal repo but i still see the glitch. I think they have preboot integrated. I am lil' lost here... I know its not a straightforward process and lots of hurdles to overcome. I just want to know for now if its been implemented. I was working on 1st strategy... so i am not sure if i have to continue my work or not. |
Using async http is causing the UI flickering when bootstraping at client side since the UI is rendered twice, 1 at server-side and 1 at client-side after each async http call.
So I came up with a home-brewed service which embeds the data from the first http call at server into rendered html so I can skip the second call and use the cached data instead at client side but still the UI is re-rendered and flickers due to the client-side bootstraping.
Is there any way I can skip the second rendering? or am I doing this in wrong way? or there is any better way to do this? should I use precache, primeCache or prime? there is no example or sample I can find on these options though.
The text was updated successfully, but these errors were encountered: