Skip to content

PersistedState null value not working #267

@dankobg

Description

@dankobg

Describe the bug

PersistedState does not seem to change when i set the current value to null, nothing happens.

<script lang='ts'>
  const count = new PersistedState<number | null>("count", 0);
</script>
<div>
  <button onclick={() => (count.current = Math.random())}>Rand</button>  // WORKS
  <button onclick={() => (count.current = null)}>Clear</button>          // DOES NOT DO ANYTHING
  <p>Count: {count.current}</p>
</div>

Don't see any reason why this should not work, null is valid json value and default serializer (JSON.stringify and parse work on null).

Reproduction

You can use this in repl if it allows localstorage, stackblitz sucks ass, nothing ever works there.

<svelte:options runes />

<script lang='ts'>
  import { PersistedState } from 'runed';
  const count = new PersistedState<number | null>("count", 0);
</script>

<div>
  <button onclick={() => (count.current = Math.random())}>Rand</button>
  <button onclick={() => (count.current = null)}>Clear</button>
  <p>Count: {count.current}</p>
</div>

Logs

System Info

System:
    OS: Linux 6.14 Fedora Linux 42 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
    Memory: 11.69 GB / 15.57 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 24.0.2 - /usr/local/bin/node
    npm: 11.3.0 - /usr/local/bin/npm
    pnpm: 10.11.0 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 136.0.7103.113
  npmPackages:
    @sveltejs/kit: ^2.16.0 => 2.21.1
    runed: ^0.28.0 => 0.28.0
    svelte: ^5.0.0 => 5.33.1

Severity

blocking all usage of runed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions