I've tried implementing the scene fade-out/in idea shown in this tutorial, which is sadly lacking in beginner-friendly implementation details.

I have an intro.tscn scene which has, at the very bottom, a ColorRect which is a child of the root node. It has the following script attached:

extends ColorRect

# Path to next scene
export(String, FILE, "*.tscn") var next_scene

onready var _anim_player := $fade

func _ready():
    _anim_player.play_backwards("fade")

func transition_to(_next_scene := next_scene):
    print("transitioning")
    _anim_player.play("fade")
    yield(_anim_player, "animation_finished")
    print("switching")
    get_tree().change_scene(_next_scene)

The intro node itself has this script attached:

extends Node2D

func _on_Timer_timeout():
    $CanvasLayer/transition_rect.transition_to("res://scenes/main.tscn")

The fade animation, timer and fade-in/out transition work as expected, but at the instant the scene switches the main.tscn can briefly be seen, as a one-frame flash, before the viewport is blacked out and the fade-in starts.

Worse still, this doesn't happen all the time, but I can't figure out what's causing it. Even the exported executable (macos) has this happening seemingly randomly.

Any ideas welcome. Thanks.