It sounds like everything is kosher as soon as you resize the window? I remember I had a similar problem a while ago and forced Unity to update its layout. I think it was via LayoutRebuilder.ForceRebuildLayoutImmediate, though it’s possible I used Canvas.ForceUpdateCanvases. I believe the latter is more expensive than the former. Here’s a thread with more discussion on it.
Hope that helps!