My colleagues and me faced the problem that a blazor component (we call it View) is recreated when a root component's StateHasChanged is called. So, at that moment the View's OnInitialized method is executed. If I understend it right, OnInitialized method is only executed once when the component is first created. But our View component had been already created and it is stored in a private field of stack type.
The code from .razor file (root component):
@foreach (var rec in _navStack){<div class = "viewport" style = "height : calc(100vh - 104px)"><div @key="rec.Id" class="h-100 @(rec == _navStack.Peek() ? "d-block" : "d-none")"> @rec.Fragment</div></div>}The problem View is stored in _navStack. When user clicks some button, root component's StateHasChanged method is called and then foreach block is executed. And when rec.Fragment (View) is rendered, View's OnInitialized method is executed. This situation causes some problems that require more details, but it is not important now.
Interesting fact - if we move <div class = "viewport"...> block outside foreach block everything works just fine!
<div class = "viewport" style = "height : calc(100vh - 104px)">@foreach (var rec in _navStack){<div @key="rec.Id" class="h-100 @(rec == _navStack.Peek() ? "d-block" : "d-none")"> @rec.Fragment</div>}</div>css styles:
.viewport { min-height: 100%; padding: 0 10px; overflow: clip;}.d-block { display: block !important;}.d-none { display: none !important;}Any guess?