Closed AmarjeetBanwait closed 5 years ago
Thanks for contacting us, @AmarjeetBanwait. When a component is being prerendered, the rendering happens once only anyway, so there is no value in such a check. If, however, you still believe you're facing an issue, where the component gets rendered twice, please share a repro project so we can investigate that.
Thanks @mkArtakMSFT Here is the repro link. Prerendering Issue
You will see weather forecast table refreshing again after rendering.
Add breakpoint in SampleData Controller. Controller will hit 2 Times.
Not sure following issue will reflect on your end or not After refreshing from browser reload button Date Format in the table will be different and after 2nd render Date will be shown differently
1st render Date format: 07-18-2019 Rerender Date format: 07/18/2019
Thanks for the details, @AmarjeetBanwait. Looks like you're experiencing this behavior on client-side Blazor. This is actually expected and by-design.
Can you please tell why this behavior is necessary in client side? Because in cases when we are fetching large data on render it makes no sense fetching it twice.
@SteveSandersonMS can you answer this question please? Thanks
When you have a client-side Blazor application that is also prerendered on the server, you have two completely separate instances of the application:
They have to be separate instances, because how could they not be? They run on different machines. As such, whatever you tell it to do, it's going to do twice.
Theoretically it could be possible for the server-side instance to fetch the data and then write it out as part of the initial HTTP response somehow (e.g., in an <input type=hidden>
or similar), and then the client-side app could pick up the data from there instead of doing its own outbound HTTP request to fetch it. But that sort of thing can't be done automatically - you would have to write code to make that happen.
In case of Prerendering, Component is rendered twice. So in this condition this will be a good idea if we have a check IsPrerendered in Component base. It makes no sense to render a component twice. This check will facilitate us to do things like
or simply