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
Open
feat(PersistedState): compile-time guard preventing undefined as a valid value in the stored type#411kraktus wants to merge 1 commit intosvecosystem:mainfrom
undefined as a valid value in the stored type#411kraktus wants to merge 1 commit intosvecosystem:mainfrom
Conversation
…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 detectedLatest commit: f1b08f6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This was referenced Feb 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
undefinedis already used internally byPersistedStateas a special case to indicate that the value is not present in storage, and in case of deserialisation failure.This make using
undefinedin user-code a footgun, because for examplepersistentState.current = undefinedis 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.