Skip to content

feat(PersistedState): compile-time guard preventing undefined as a valid value in the stored type#411

Open
kraktus wants to merge 1 commit intosvecosystem:mainfrom
kraktus:no_undefined_pstate
Open

feat(PersistedState): compile-time guard preventing undefined as a valid value in the stored type#411
kraktus wants to merge 1 commit intosvecosystem:mainfrom
kraktus:no_undefined_pstate

Conversation

@kraktus
Copy link

@kraktus kraktus commented Feb 27, 2026

undefined is already used internally by PersistedState as a special case to indicate that the value is not present in storage, and in case of deserialisation failure.

This make using undefined in user-code a footgun, because for example persistentState.current = undefined is not working as expected, being a NOOP instead of emptying the state.

While this is technically a breaking-change, I consider it a patch because the user-code impacted is buggy anyway.

Alternatively another approach would be allow undefined state. A draft PR is available here: #408. I did not get to the end of it, because the issue is that undefined has no valid JSON value, so it would require additional (de)serialisation logic, especially for custom ones.

…valid value in the stored type

`undefined` is already used internally by `PersistedState` as a special case to indicate that the value is not present in storage, and in case of deserialisation failure.

This make using `undefined` in user-code a footgun, because for example `persistentState.current = undefined` is not working as expected, being a NOOP instead of emptying the state.

While this is technically a breaking-change, I consider it a patch because the user-code impacted is buggy anyway.

Alternatively another approach would be allow undefined state. A draft PR is available here: svecosystem#408. I did not get to the end of it, because the issue is that undefined has no valid JSON value, so it would require additional (de)serialisation logic, especially for custom ones.
@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2026

🦋 Changeset detected

Latest commit: f1b08f6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
runed Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant