Global Values on Layout not available

Good Day

I have an issue with the global values that I cannot seem to understand.

On the main layout I set a global variable on load and populate it.
I place a label on the header of the layout and on a new page and reference both labels to that global value.

On the initial load the header and page display the value.
However on page refresh only label in the header displays the value. I have to navigate away from the page and back for it to display again.

Hi @DarrenW,

I tried to reproduce this problem with the attached application however it seems to work fine. The global property is display as expected in the layout and the page itself.
BlazorNumeric (5.9 KB)

Hi @korchev

Thanks for the reply, I see what you are saying it is functioning correctly if I have a set string.

Where the issue seems to be on my side after checking is that I am assigning the Global from ProtectedSessionStorage.

I am trying the following:


using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage;

namespace Optstore.Layouts
{    public partial class MainLayoutComponent
        ProtectedSessionStorage sessionStorage { get; set; }


protected async System.Threading.Tasks.Task Load()
    var accid = await sessionStorage.GetAsync<string>("accid");
    Globals.companyid = accid.Value.ToString();

The Globals in the layout is set correctly but the page seems to render before the global is set for the page. As I navigate within the app the globals in the layout and the page are correct and available however on page refresh the page Globals do not get the populated.

It seems that the page loads/renders before the layout has completed the Globals population.

Yes, this is how Blazor works. Having async code in the layout does not stop rendering and the page continues to execute. As a result the global property may not be available immediately in the page