Start by peeling the potatoes and slicing them evenly, about ¼ inch thick. Slice the onion into thin rings. I like to use a mandoline here for uniform slices because it ensures even cooking.
Lightly grease your baking dish with nonstick spray. Arrange the potato slices and onion rings in alternating layers. Staggering them ensures each bite has a perfect balance of potatoes and onions.
Melt butter in a medium saucepan over medium heat. Whisk in flour and salt for one minute, then gradually add milk, stirring until thickened. Once thick, remove from heat and stir in shredded cheese until smooth and creamy.
Pour the cheese sauce evenly over the layered potatoes. Cover the dish with aluminum foil and bake in a preheated 400°F oven for 85–90 minutes, or until the potatoes are tender. For a golden top, switch to broil for a few minutes at the end.
Once baked, season with salt and pepper to taste. Let it sit for a few minutes to firm up slightly before serving, then scoop onto plates and enjoy that gooey, cheesy perfection.