Garbage when updating display style

In my settings screen, I have sometimes garbage in a button label after changing the display style:

It was caused by this code:

            selectedMonitor = selMonitor.index;
            if (selectedMonitor != previousMonitor)
            {
                selResolution.AddToClassList("d-none");
                btnApplyResolution.RemoveFromClassList("d-none");
            }
            else
            {
                selResolution.RemoveFromClassList("d-none");
            }

‘d-none’ is a display: none style class.

I have changed it like so to make it work (Unity 2023.2):

        private async Awaitable selectMonitor()
        {
            selectedMonitor = selMonitor.index;
            if (selectedMonitor != previousMonitor)
            {
                await Awaitable.EndOfFrameAsync();
                selResolution.AddToClassList("d-none");
                await Awaitable.NextFrameAsync();
                btnApplyResolution.RemoveFromClassList("d-none");
            }
            else
            {
                selResolution.RemoveFromClassList("d-none");
            }
        }

As of now I don’t see garbage anymore.

Interesting. When were you calling the previous code? It’s somewhat important which stage of the frame you make your UI style changes.

I call either by clicking on the selector (custom visual element) or through the new inputsystem.