Skip to content

PersistedState: It's not possible to clear a nullable persisted state #388

@AndersRobstad

Description

@AndersRobstad

Describe the bug

It is not possible to remove the value of a PersistedState thats possibly null or undefned. Setting its value to either null or undefined does not update either the value inside the storage nor the state it self.

Reproduction

const state = new PersistedState<{test: string} | null>(
		`${INITIAL_FILTER_STATE_KEY}-${viewId}`,
		null,
		{
			storage: 'session'
		}
	);
// state.current is now null
state.current = {test: "string"}
// state.current is now {test: "string"}
state.current = null
// state.current is now still {test: "string"} and thats the value in session storage as well

Logs

System Info

System:
    OS: macOS 26.0.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 112.50 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.15.0 - /Users/andersrobstad/.nvm/versions/node/v22.15.0/bin/node
    npm: 10.9.2 - /Users/andersrobstad/.nvm/versions/node/v22.15.0/bin/npm
    pnpm: 10.15.1 - /Users/andersrobstad/Library/pnpm/pnpm
  Browsers:
    Brave Browser: 137.1.79.118
    Chrome: 142.0.7444.162
    Edge: 142.0.3595.80
    Firefox: 138.0.4
    Safari: 26.0.1

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    triagePending triage by a maintainer to give it proper labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions