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

Add @eschricht/nuxt-color-mode module #1069

Closed
wants to merge 2 commits into from

Conversation

Eschricht
Copy link
Contributor

πŸ”— Linked issue

resolves #1064

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Added @eschricht/nuxt-color-mode module

@atinux
Copy link
Member

atinux commented Sep 11, 2024

Thank you for working on this module, have you considered contributing to the main one?

@nuxtjs/color-mode support SSR and SSG actually (we don't need cookies to support this)

@Eschricht
Copy link
Contributor Author

Eschricht commented Sep 11, 2024

Thank you for working on this module, have you considered contributing to the main one?

@nuxtjs/color-mode support SSR and SSG actually (we don't need cookies to support this)

There has been multiple issues / pull requests on the main module to support both cookies and the sec-ch-prefers-color-scheme header but AFAIK there's no progress.

Examples:
nuxt-modules/color-mode#188
nuxt-modules/color-mode#218
nuxt-modules/color-mode#209

But I'd happy to help out with the main module if you'd like!

With full SSR support, I mean that it supports fetching system color scheme from the server (via the sec-ch-prefers-color-scheme) on supported browsers and avoid the flickering issue described here

Also, the server cannot access browsers local storage so anything stored there will be resolved on the client only. Using cookies instead solves that issue as those are shared with the server.

@atinux
Copy link
Member

atinux commented Sep 13, 2024

I just released the support for cookie storage!

Are you happy to help on sec-ch-prefers-color-scheme header detection? (I guess helping your review on nuxt-modules/color-mode#219)

@Eschricht
Copy link
Contributor Author

Sweet! I'll take a look at the sec-ch-prefers-color-scheme header during the weekend πŸ‘

I'll close this one

@Eschricht Eschricht closed this Sep 13, 2024
@sharifzadesina
Copy link

sharifzadesina commented Sep 14, 2024

@atinux Even with cookie storage it doesn't work with SSR. color mode gets updated only after app mount and interestingly, it is not reactive and usages like: <img :src="/img/logo-${colorMode.value}.svg"> doesn't work for whatever reason. (src stays on the old value and doesn't get update after mount.)

Copy link
Member

atinux commented Sep 15, 2024

please open an issue there to discuss about it.

it is hard to handle all cases so there are specific reasons why it works this way. like how do you handle pre-rendering or cached pages?

@sharifzadesina
Copy link

@atinux I don't have any pre-render or caching if you mean that. by the way @Eschricht's module works without problem.

Copy link
Member

atinux commented Sep 16, 2024

Yes but when you make a module you need to think of all use cases, this is why I had to make compromises.

BTW, how does it work for you <img> if the preference is system and the server cannot detect the user color mode on the server?

@sharifzadesina
Copy link

sharifzadesina commented Sep 16, 2024

@atinux I changed the preference from system to light, so we will always have a color mode before mounting.
The problem is that the module adds HTML class successfully before mount, but it is not able to detect a valid colorMode.value before mount (even with cookie storage) and it causes a lot of problems.
It is supposed to detect user preferences in cookie storage.
I need to create a new issue with a demo for you.

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 this pull request may close these issues.

[Module Listing Request]: @eschricht/nuxt-color-mode
3 participants