Scene loading bug in 2022 vs 2020?

Hi,

I updated my project from version 2020 to version 2022 and am seeing a discrepancy in the way scenes are loaded.

To reproduce, I can add this code (and an empty scene called “X”) to a new project.

public class SceneBugTest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(LoadScene("X"));
    }

    public IEnumerator LoadScene(string scene, ThreadPriority priority = ThreadPriority.Low)
    {
        Application.backgroundLoadingPriority = priority;
        yield return new WaitForSeconds(0.1f);
        var operation = SceneManager.LoadSceneAsync(scene);

        operation.allowSceneActivation = false;

        Debug.Log($"Loading scene: {scene}");

        while (!operation.isDone)
        {
            yield return null;
        }
    }
}

If I click away from the editor and click back in (or alt+tab back in) then it automatically changes to scene “X”. The expected behavior is that scene “X” should not be switched to until “allowSceneActivation” is set to true. This works fine in Unity 2020, but not in Unity 2022. Any help?