Coder Social home page Coder Social logo

Comments (8)

microcipcip avatar microcipcip commented on August 12, 2024 1

then it incorrectly sets the cookie - which seems to be redundant. My PR handled this.

You're right, I did it this way because the cookie that is set is invalid and immediately dismissed by the browser (set to expire in 1970), the code is also easier to understand.

I had initially tried with a more sophisticated approach with a filter (I implemented it in the set method, similar to your code), but I think that always setting it to invalid is more performant because before we had to check if the cookie existed with get and then set it. Now we only do set regardless, without additional logic specific to Frontend and SSR.

Anyway, let me know if it works 🤞

from cookie-universal.

dominikjasek avatar dominikjasek commented on August 12, 2024 1

I tested it and it works. Thanks for the release ❤️

from cookie-universal.

dominikjasek avatar dominikjasek commented on August 12, 2024

I prepared PR which fixes this #128

from cookie-universal.

microcipcip avatar microcipcip commented on August 12, 2024

I don't understand this use case. Why would you set the cookie and remove it in the same request?

from cookie-universal.

dominikjasek avatar dominikjasek commented on August 12, 2024

At first glance this seems useless. However, when the application is really big and complex, this scenario may happen and thus this use-case is valid.

For example, my scenario is as follows:

  • in nuxtServerInit, i set cookies including myCookie
  • in page component there is a bunch of logic with plenty of $fetch functions
  • one of those function is encapsulated in a try catch block and if the call fails, we want to remove a cookie myCookie

from cookie-universal.

microcipcip avatar microcipcip commented on August 12, 2024

You convinced me :). I have pushed an update, can you please check v2.2.0? Apologies for not using your Pull Request, I wanted to add unit tests and there was an issue with setResponseCookie which would have run also in client side breaking the app. Let me know if it works.

from cookie-universal.

dominikjasek avatar dominikjasek commented on August 12, 2024

Thanks! I haven't tested yet but as far as I can see from changes, it lacks validation whether the cookie was set or not.

For example, if this is your nuxtServerInit function:

nuxtServerInit() {
  this.$cookies.remove('cookieWhichHasNeverBeenSet')
}

then it incorrectly sets the cookie - which seems to be redundant. My PR handled this.

from cookie-universal.

microcipcip avatar microcipcip commented on August 12, 2024

Awesome!

from cookie-universal.

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.