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

Client-server mismatch when the color mode is set to system #5227

Closed
obulat opened this issue Dec 2, 2024 · 0 comments · Fixed by #5236 or #5237
Closed

Client-server mismatch when the color mode is set to system #5227

obulat opened this issue Dec 2, 2024 · 0 comments · Fixed by #5236 or #5237
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: frontend Related to the Nuxt frontend

Comments

@obulat
Copy link
Contributor

obulat commented Dec 2, 2024

Description

When the color mode is set to default system, and the user's preference is dark, there is a client-server mismatch which probably causes the page to re-render.

The problem is with the use of usePreferredColorScheme in osColorMode: on the server, the media query is not available, so the value is set to default no-preference, setting the effective color mode to "light". If the user's system is set to dark, the media query returns "dark" on the client. Normally, this would not cause a mismatch since only the rendering of the CSS values would change, but we use different icons (for the theme switcher - sun/moon, and for the licenses) in different color modes, so this causes client-server mismatch.

Reproduction

  1. Run the app in dev mode, and set the color mode to system.
  2. Go to https://localhost:8443/search?q=cat
  3. Refresh the app
  4. See error: console logs about hydration mismatch.

Screenshots

runtime-core.esm-bundler.js?v=bd1a66ef:50 [Vue warn]: Hydration attribute mismatch on <use href=​"/​_nuxt/​assets/​svg/​sprite/​icons.svg#sun" data-v-inspector=​"src/​components/​VIcon/​VIcon.vue:​89:​5" data-v-0335fe76>​…​</use>​ 
  - rendered on server: href="/_nuxt/assets/svg/sprite/icons.svg#sun"
  - expected on client: href="/_nuxt/assets/svg/sprite/icons.svg#moon"

Additional context

@obulat obulat added 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: frontend Related to the Nuxt frontend and removed 🚦 status: awaiting triage Has not been triaged & therefore, not ready for work labels Dec 2, 2024
@openverse-bot openverse-bot moved this to 📋 Backlog in Openverse Backlog Dec 2, 2024
@obulat obulat added the 💻 aspect: code Concerns the software code in the repository label Dec 2, 2024
@openverse-bot openverse-bot moved this from 📋 Backlog to 🏗 In Progress in Openverse Backlog Dec 2, 2024
@openverse-bot openverse-bot moved this from 🏗 In Progress to ✅ Done in Openverse Backlog Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🛠 goal: fix Bug fix 🟧 priority: high Stalls work on the project or its dependents 🧱 stack: frontend Related to the Nuxt frontend
Projects
Archived in project
1 participant