Comments (14)
@raymayemir We are working around it, manually getting the cookies both in the entry-client (but it's not immediate) and in the component we are needing the data, before it requests it.
Useful info:
-Remember a coookie can only have 4kb, so maybe all your store can't live in one cookie.
-Vuex-persist (https://github.com/championswimmer/vuex-persist/) lets you reduce your store, so you save all you need in different cookies.
from vuex-persistedstate.
Or make it so references to window object are removed, then on mount() we can call some static method to restore state.
I don't mind the first frame of the app shows things in the default state (so SSR + client render are the same), but we need the references to window object removed so that the library would work in a SSR environment.
from vuex-persistedstate.
Is there any update on this? I'm trying to make this work with Nuxt.js but no luck so far. Thanks.
from vuex-persistedstate.
👍 same issue for me.
from vuex-persistedstate.
So it turned out the customization example was currently not reflecting the latest changes to the underlaying API. I've updated it accordingly and if followed correctly, it would solve this SSR issue;
import { Store } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import * as Cookies from 'js-cookie'
const store = new Store({
// ...
plugins: [
createPersistedState({
storage: {
getItem: (key) => Cookies.getJSON(key),
setItem: (key, value) => Cookies.set(key, value, { expires: 3, secure: true }),
removeItem: (key) => Cookies.remove(key);
}
})
]
})
As you can see, you'll have to overwrite the storage
key instead of the getState
and setState
keys. If it's still not working, please open another issue.
from vuex-persistedstate.
Its not working for me. The cookie comes back to original every time i update the page,
from vuex-persistedstate.
You managed to solve?
from vuex-persistedstate.
Still not working for me too... Lack of documentation
from vuex-persistedstate.
Still not working for me too... Lack of documentation
@edum18
what exactly is not working?
from vuex-persistedstate.
@robinvdvleuten Is there any update and/or a new issue regarding this?
I implemented your method into my Nuxt app and the cookie is being properly set, but when I load the page, I'm getting Cookies.getJSON(key) = undefined
. Not sure why, but this has always been my issue with trying to grab cookies on the server-side of Nuxt.
Please advise, if you could!
from vuex-persistedstate.
@bswank first things that comes to mind is that you have not set secure
to false
when writing to cookies and thus no cookie will be persisted on localhost.
from vuex-persistedstate.
@robinvdvleuten Thanks for your response. The cookie is being persisted just fine and secure is set to false.
The problem I've faced in the past is that I call Cookies.set()
upon login, and on nuxtServerInit
, or asyncData
when I'm trying to get that cookie prior to render, it's always undefined. Your solution produces the same result.
Just wondering if this is possible to fix. I need my store/ccokies prior to render so I can pre-fetch data. Otherwise, I have no place to store a logged-in user ID, etc.
from vuex-persistedstate.
@bswank I don't know what nuxtServerInit
and asyncData
does, sorry. I am not a Nuxt.js user and this library predates them. The cookies
library does not depend on Nuxt.js, so if anything there is undefined, something else may go wrong. If you think that this is an issue with vuex-persisted state, please open a new issue with a codesandbox containing the issue. I simply do not have the time to guess everybody's Vue / Nuxt / Vuex setup.
from vuex-persistedstate.
@robinvdvleuten No worries; thanks anyway! Just wanted to see if your proposed solution was usable on the server-side of Nuxt.
from vuex-persistedstate.
Related Issues (20)
- how can i use dynamic key HOT 2
- Not working with Secure-Ls HOT 1
- High Severity: Prototype Pollution vulnerability in module shvl
- How to encrypt sessionStorage using secure-ls? HOT 1
- Feature Request: Code Examples / Documentation for Options
- Lots of plugins? HOT 1
- VueDevtools not data HOT 1
- Example needed: path options and namespaces HOT 1
- secure-ls | Uncaught Error: Could not parse JSON HOT 2
- Wrong data after restore. HOT 1
- One cookie by module with JS-COOKIE
- Storage option with Js cookie stops working suddenly HOT 1
- vuex-persistedstate does not follow vuex plugin guidelines HOT 2
- Newbe Question - Restore data from localStore to Vuex on page reload in Nuxt.js HOT 2
- Unable to access data from Vuex after rehydration in Nuxt.js HOT 2
- Clearing localstorage in developer tools not working HOT 2
- Feature Request: Support Pinia HOT 1
- [Feature Request] can `paths` option support `function` and `Regex`?
- It's not clear to me if Vuex 3 and Vue 2 are supported by vuex-persistedstate 4
- Exemple using cookie-universal-nuxt HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-persistedstate.