Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it normal that getting the color mode preference takes 3-5 seconds? #291

Open
molul opened this issue Sep 23, 2024 · 0 comments
Open
Labels
question Further information is requested

Comments

@molul
Copy link

molul commented Sep 23, 2024

In my Nuxt app, it takes like 3-5 seconds before I see my custom theme select button on the screen.

You can check it here (the button will appear next to the flag button, either at the top bar on mobile or at the bottom of left sidebar on desktop, after a few seconds): https://buscamusicos-ui-nuxt-git-main-moluls-projects.vercel.app/es

This is my custom component:

<script setup lang="ts">
import BaseMenuItem from '~/components/menus/BaseMenuItem.vue'

interface SelectThemeButtonProps {
  menuType: 'sidebar' | 'mobile-header' | undefined
}
const props = defineProps<SelectThemeButtonProps>()

const colorMode = useColorMode()

const icon = ref()

// ---------------------------
// switchColor
// ---------------------------
function switchColor() {
  colorMode.preference = colorMode.preference === 'light' ? 'dark' : 'light'
  switchIcon()
}

// ---------------------------
// switchIcon
// ---------------------------
function switchIcon() {
  icon.value = colorMode.preference === 'light' ? 'solar:moon-bold' : 'solar:sun-2-bold'
}

// ---------------------------
// onMounted
// ---------------------------
onMounted(() => {
  switchIcon()
})
</script>

<template>
  <BaseMenuItem :menu-type="props.menuType" :icon="icon" @click="switchColor" />
</template>

I had to put the icon switch on onMounted because otherwise I would get a hydration error. Guess that's why it takes so long, but I don't know how to put it outside onMounted.

No special configuration. Storage is set to localStorage.

I thought it was due to Nuxt icon module, but the other icons appear quickly.

Any help is greatly appreciated.

@molul molul added the question Further information is requested label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant