This post is over 1 year old. Facts and opinions may have changed since the publication date. Contact me for any clarifications before jumping into any conclusions.

Just fixed the flickering issue by inlining the required JavaScript, which is a really small snippet. If you’re curious about the code I’m using to toggle between the dark and light themes, following the user’s choice and falling back to the OS settings, here it is:

const mql = window.matchMedia('(prefers-color-scheme: dark)');

function toggleT (to) {
localStorage.setItem('t', to);
theme(mql);
}

function theme (query) {
const userOption = localStorage.getItem('t');

document.body.id = userOption === null
? (query.matches ? 'dark' : '')
: (userOption === 'd' ? 'dark' : '');
}