By falling back to the platform preference for the color-scheme0 if
no local-storage key is set, we can improve user experience on first
load.
Use the widely available1window.matchMedia method to query that
preference in the fallback case.
While the prefers-color-scheme is relatively new, as browser support
appeared only ~2 years ago, it does not matter much here as older
browser will simply return a false match, thus the current theme
default is kept for them.
By falling back to the platform preference for the color-scheme0 if no local-storage key is set, we can improve user experience on first load.
Use the widely available1
window.matchMedia
method to query that preference in the fallback case.While the
prefers-color-scheme
is relatively new, as browser support appeared only ~2 years ago, it does not matter much here as older browser will simply return a false match, thus the current theme default is kept for them.Signed-off-by: Thomas Lamprecht thomas@lamprecht.org