Every dark mode implementation has the same enemy: the flash.

The page renders in light mode, then instantly switches to dark. It happens because JavaScript applies the CSS class after the HTML is already painted -- and by then it's too late.

Why It Happens

Browsers paint HTML before JavaScript runs. By the time your JS reads localStorage and adds dark to <html>, the first frame is already done.

The only real fix is a blocking inline script in <head> that runs before any rendering. That's what next-themes handles automatically.