Giter Club home page Giter Club logo

Comments (5)

halfmoonui avatar halfmoonui commented on August 30, 2024 1

What would be the benefit of doing this? The way the cookie is stored at this moment does not require serialization or parsing.

More importantly, you actually want the darkModeOn to be readable on the server side. This is especially important if you are using backend frameworks like Laravel/Django/Rails where the view function generates and returns the template. On those types of stacks, the saved dark-mode preference can be set server side without JS (see: #28 (comment))

from halfmoon.

qgustavor avatar qgustavor commented on August 30, 2024 1

From a quick research GDPR don't applies only to cookies but localStorage too. For me the best option to avoid storing info about the user is not storing any information at all until the user interacts with the page, which I already suggested here. If the user interacts with the page wanting to change their dark mode preference then it's safe to assume that the user gave consent to store this information, which, from what I understand, is not a issue with GDPR.

Using a cookie and server side rendering it's possible to avoid the unwanted flash of light mode, but there are many solutions. One that avoids this issue without using real server side rendering is using service workers to emulate server side rendering (demo) which is, of course, too hard to implement. I think that the best option for the framework is providing a simple implementation that will solve this issue for most users and documenting what the optional JS library does so anyone can implement their own toggleDarkMode() function using localStorage, or Service Workers, or React, or Vue, or Choo... whatever.

from halfmoon.

TheKingDave avatar TheKingDave commented on August 30, 2024

I understand the point made in #28.

But I could see future users of this framework who do not want their users to need to use cookies. Especially in times of GDPR.
It could of course be argued that they are essential cookies.

Maybe the option to choose between cookie and localStorage could be a possibility.

With serialization/parsing I meant:

halfmoon/js/halfmoon.js

Lines 47 to 75 in 37d569f

// Create cookie
createCookie: function(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toGMTString();
}
else {
expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
},
// Read cookie
readCookie: function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return c.substring(nameEQ.length,c.length);
}
}
return null;
},

from halfmoon.

halfmoonui avatar halfmoonui commented on August 30, 2024

After thinking about this issue quite a bit, I think @qgustavor has the right idea. If GDPR applies to both cookies and localStorage, then there doesn't seem to be any advantage using localStorage. This could be made into a choice for the user, that is, pass in a parameter to select whether you want to save it in a cookie or in localStorage, but that seems like extra complexity without any real benefit.

I especially agree with the point that the framework should provide a simple implementation (ideally one that works for 95% of users in a way that they don't even have to think about it). The rest will have to override the method for more complex use cases. For example, I had to override the toggleDarkMode() method for the pages with iFrames in them on the documentation website.

Moreover, I would say the cookie definitely falls under essential. So, if I push what @qgustavor suggested in the next update (that is, cookie is not set until the user interacts with the page), there should be no issue going forward.

from halfmoon.

halfmoonui avatar halfmoonui commented on August 30, 2024

The whole dark mode preference implementation has been overhauled in v1.1.0. Please refer to this page of the docs: https://www.gethalfmoon.com/docs/core-javascript-library/

Basically, what I wrote in my previous comment has been implemented in the framework. I will go ahead and close this issue. You can re-open it if you think the issue is still not resolved, or open another issue.

from halfmoon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.