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

Having interval inside a persistent store breaks persisting #281

Open
KarelVendla opened this issue Feb 26, 2024 · 0 comments
Open

Having interval inside a persistent store breaks persisting #281

KarelVendla opened this issue Feb 26, 2024 · 0 comments
Labels
🔍️ pending triage This issue needs to be looked into

Comments

@KarelVendla
Copy link

Describe the bug

I have a store which persists data as cookies.
I added stateful interval that I am sharing across components, this broke the store persistence.

anything related to the interval is not persisted.

the store persistence options

  {
    persist: {
      paths: ["stripeSubscriptionParams", "checkoutSuccess"],
      storage: persistedState.cookiesWithOptions({
        maxAge: HoursToSeconds(23),
      }),
    },
  },

row in the store

const { durationRemaining, stopTicking, startTicking } = useCountdown(MinutesToSeconds(10));

useCountdown composable

export function useCountdown(duration: number) {
  const durationRemaining = ref<number>(duration);
  const interval = ref<ReturnType<typeof setInterval>>();
  function startTicking() {
    durationRemaining.value = duration;
    interval.value = setInterval(() => {
      if (durationRemaining.value > 0) {
        durationRemaining.value--;
      } else {
        clearInterval(interval.value);
      }
    }, 1000);
  }

  function stopTicking() {
    clearInterval(interval.value);
  }

  return {
    durationRemaining,
    stopTicking,
    startTicking,
  };
}

Reproduction

provided some code in bug description.

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
    Memory: 5.50 GB / 15.89 GB
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.52)
    Internet Explorer: 11.0.19041.3636


### Used Package Manager

npm

### Validations

- [X] Follow our [Code of Conduct](https://github.com/prazdevs/pinia-plugin-persistedstate/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guide](https://github.com/prazdevs/pinia-plugin-persistedstate/blob/main/CONTRIBUTING.md).
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] The provided reproduction is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
@KarelVendla KarelVendla added the 🔍️ pending triage This issue needs to be looked into label Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍️ pending triage This issue needs to be looked into
Projects
None yet
Development

No branches or pull requests

1 participant