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

Forced Color Mode Per Page Causes Unintended Behavior with nuxt-link in Nuxt3 #277

Open
lhoucinecherif opened this issue Aug 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@lhoucinecherif
Copy link

Hi,
I am using Nuxt3 with the colorMode module and fetching page-specific color modes from a Sanity backend. I want to force a specific color mode on certain pages. While the forced color mode works initially, clicking on the active nuxt-link for the current page causes the color mode to change unexpectedly.

Version

@nuxtjs/color-mode: 3.4.1
nuxt: 3.11.2

Reproduction Link

https://stackblitz.com/edit/github-qvp2nk-wgy2hy?file=middleware%2Fcolor-mode.global.ts

Steps to reproduce

  1. Navigate to a page with a forced color mode. (light or dark)
  2. Click on the active link of the current page.

What is Expected?

When navigating to a page with a forced color mode, the page should stay in the forced color mode, and clicking on the active nuxt-link should not change the color mode.

What is actually happening?

On pages with a forced color mode, clicking on the active link causes the color mode to change unexpectedly.

Thanks.

@lhoucinecherif lhoucinecherif added the bug Something isn't working label Aug 1, 2024
@atinux
Copy link
Contributor

atinux commented Sep 13, 2024

Nice catch @lhoucinecherif

This is quite weird, I suspect the issue comes from to the fact that you add the meta from a Nuxt middleware which is not called on the same route, but we use router.afterEach which is called anyway:

: to.meta.colorMode

Could you try to use a Nuxt plugin instead an use useRouter().beforeEach() to update to.meta and see if this solves it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants