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

⚠️ Issue - The implementation of themes from Shiki is not working properly. #8163

Closed
gxlpes opened this issue May 2, 2024 · 1 comment

Comments

@gxlpes
Copy link

gxlpes commented May 2, 2024

Even tough I have a shikiConfig estabalished with a correct implementation of dark mode

 shikiConfig: {
      wrap: true,
      themes: {
        light: 'github-dark',
        dark: 'github-light',
      },
    },
<script is:inline>
  const setThemeColor = () => {
    const metaThemeColor = document.querySelector('meta[name=theme-color]')
    if (metaThemeColor) {
      if (document.documentElement.classList.contains('dark')) {
        metaThemeColor.setAttribute('content', 'black')
      } else {
        metaThemeColor.setAttribute('content', 'white')
      }
    }
  }

  const handleToggleClick = () => {
    const htmlElement = document.documentElement
    const bodyElement = document.body

    htmlElement.classList.toggle('dark')
    bodyElement.classList.toggle('dark')

    const isDark = htmlElement.classList.contains('dark')
    localStorage.setItem('theme', isDark ? 'dark' : 'light')

    if (isDark) {
      htmlElement.setAttribute('data-color-scheme', 'dark')
    } else {
      htmlElement.removeAttribute('data-color-scheme')
    }

    setThemeColor()
  }

  document.getElementById('theme-toggle').addEventListener('click', handleToggleClick)

  document.addEventListener('astro:after-swap', () => {
    localStorage.theme === 'dark'
      ? document.documentElement.classList.add('dark')
      : document.documentElement.classList.remove('dark')
  })

  const theme = localStorage.getItem('theme') || 'light'
  if (theme === 'light') {
    document.documentElement.classList.remove('dark')
  } else {
    document.documentElement.classList.add('dark')
    document.body.classList.add('dark') // Also add 'dark' class to body
  }
  setThemeColor()
</script>

My Shiki is not changing its theme.

@sarah11918
Copy link
Member

Hi! I'm closing this issue because, as I mentioned in the linked PR here, we have an open PR to address this! 🙌 Thank you for bringing it to our attention, and sorry we didn't get the PR completed before you needed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants