After further testing this issue is only relevant with fabric and optifine. Minecraft Forge works fine.
But this is a launcher issue. It works fine when I use the bundled JRE that comes with the launcher by default. But when I try to use openJDK it doesn't launch the game.
After further testing this issue is only relevant with fabric and optifine. Minecraft Forge works fine.