color-mode icon indicating copy to clipboard operation
color-mode copied to clipboard

lib is ignoring initial "colorMode/preference" and switches to "system"

Open piotrku opened this issue 3 years ago • 1 comments

Version

@nuxtjs/color-mode: 2.1.11 nuxt: 2.15.7

is there any reason for the lib to automatically switch always to 'system' preferences although non regarding the initial config in nuxt.config.js?

colorMode: {
    preference: 'light', // default value of $colorMode.preference
    fallback: 'light', // fallback value if not system preference found
    classSuffix: "", // removing -mode suffix for Tailwind Dark mode support
    hid: 'nuxt-color-mode-script',
    storageKey: 'nuxt-color-mode'
  },

I check this on main component mounted:

    console.log('value:', this.$colorMode.value);
    console.log('forced:', this.$colorMode.forced);
    console.log('preference:', this.$colorMode.preference);

    setTimeout(() => {
      console.log('value:', this.$colorMode.value);
      console.log('forced:', this.$colorMode.forced);
      console.log('preference:', this.$colorMode.preference);
    }, 10);

and the result is:

image

I expect it to stay in my initial 'light' mode - instead of switching to system's dark

piotrku avatar Dec 14 '21 12:12 piotrku

Is there any update on this?

jillztom avatar Apr 01 '22 14:04 jillztom

I'm having the same issue using Nuxt3 and Tailwind.

TJacoob avatar Apr 17 '23 15:04 TJacoob

Close as this has been stable for a long while. If you still face a similar issue with the latest module on Nuxt 3, open a new issue with minimal reproductions. Thanks.

antfu avatar Jul 03 '23 19:07 antfu

In your app.vue, add this code to force the color mode

<script setup>
const colorMode = useColorMode();

onMounted(async () => {
  await nextTick();
  colorMode.preference = "light";  // or dark
});
</script>

bayramorhan avatar Mar 06 '24 14:03 bayramorhan