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

Dynamic class binding not working as expected with Session Storage #265

Closed
4 tasks done
naseefpv opened this issue Dec 18, 2023 · 4 comments
Closed
4 tasks done

Dynamic class binding not working as expected with Session Storage #265

naseefpv opened this issue Dec 18, 2023 · 4 comments
Labels
❓ question Further information is requested

Comments

@naseefpv
Copy link

Describe the bug

I installed a pinia-plugin-persistedstate with latest Nuxt and created a store with persist enabled by Session storage class.
Tried to bind an element class with the state from the above store, it updates the class correctly without persist data but when reload with the persist data, class binding is not working.
please refer the stackbliz below
https://stackblitz.com/edit/nuxt-starter-ugwj2c?file=stores%2Fmain.js

Reproduction

.

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
    Memory: 2.69 GB / 15.49 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
    bun: 1.0.16 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 99.1.36.116
    Chrome: 119.0.6045.123

Used Package Manager

npm

Validations

@naseefpv naseefpv added the 🔍️ pending triage This issue needs to be looked into label Dec 18, 2023
@prazdevs
Copy link
Owner

Hi, thanks for the proper reproduction :)

This is an SSR related issue:
Since you are using session storage, the value is only stored client-side, but the page is rendered server side so it'll use whatever value is in pinia at the time, that is the default ('initial-text').

To have what you want working you need to use ssr: false in your nuxt config :)

@prazdevs prazdevs added ❓ question Further information is requested and removed 🔍️ pending triage This issue needs to be looked into labels Dec 18, 2023
@Dev-R
Copy link

Dev-R commented Dec 21, 2023

Hi @prazdevs,

Firstly, thank you for your exceptional work on Pinia-persistedstate!

I have a question unrelated to this issue.

I've set up a store called 'profile' and configured it to use persistent storage as follows:

// profile.store.ts

/**
 * Manages the profile store and its state.
 */
export const useProfileStore = defineStore('profile', () => {
    ...
    return {
        ...
    }
}, {
    // Pinia persist configuration
    persist: {
        storage: persistedState.localStorage,
    }
})

Now, I'm looking for a way to reset or clear the store state from the storage. I attempted the following approach, but it doesn't seem to work:

const clearProfileStoreState = () => {
    localStorage.removeItem('profile');
}

Any guidance on how to achieve this would be greatly appreciated!

Thank you!

@prazdevs
Copy link
Owner

Hi @Dev-R calling such a function worked on my side, you may want to open a proper issue with a proper reproduction repo so i could eventually investigate and help you with it.

I'll be closing this one since og issue should be solved

@oawebdev
Copy link

Hi, thanks for the proper reproduction :)

This is an SSR related issue: Since you are using session storage, the value is only stored client-side, but the page is rendered server side so it'll use whatever value is in pinia at the time, that is the default ('initial-text').

To have what you want working you need to use ssr: false in your nuxt config :)

Hello!
Do you have any solution for this issue when ssr enabled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓ question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants