mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-26 09:16:03 +03:00
[PR #4799] [MERGED] fix(common): PersistenceService call site compat #4943
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#4943
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/4799
Author: @CuriousCorrelation
Created: 3/2/2025
Status: ✅ Merged
Merged: 3/3/2025
Merged by: @jamesgeorge007
Base:
next← Head:fix/persistence-compat📝 Commits (4)
b8daf69fix(common):PersistenceServicecall site compat96f9967fix: lintf75be09fix(common): docs and deprecation warning for legacy8572ed2fix(common): default conf store-like tolocalStorage📊 Changes
4 files changed (+137 additions, -27 deletions)
View changed files
📝
packages/hoppscotch-common/src/services/persistence/__tests__/index.spec.ts(+56 -0)📝
packages/hoppscotch-common/src/services/persistence/index.ts(+71 -5)📝
packages/hoppscotch-common/src/services/tab/graphql.ts(+5 -11)📝
packages/hoppscotch-common/src/services/tab/rest.ts(+5 -11)📄 Description
This PR fixes some of the inconsistencies in calls to
PersistenceServicearound double serialization/deserialization.Legacy
PersistenceServicecalls are serialized at the call site, for example:Although
kernel'sStore.setautomatically serializes value for storage (andStore.getdeserializes automatically as well):The legacy approach still works due to how platform-dependent serialization/deserialization handles
stringvalues specifically. When we callJSON.stringify(data)in legacy modules, we're converting an object to a JSON string.When this string is passed to
persistenceService.setLocalConfig(), it goes through the store implementation where<platform>.<stringify>()is used. When<platform>.<stringify>()receives a primitive string value (which we've already stringified), it simply treats it as a regular string value and serializes it accordingly.During retrieval,
<platform>.<parse>()deserializes this back into a string.Basically, this works due to a "wrapping" pattern that the data goes through:
This is definitely not ideal:
JSON.stringify(for legacy method calls)This PR introduces new methods
set,getandremovein order to incrementally refactor existing code to the correct usage while keeping the codebase stable for backwards compatibility.For future changes, it's important to note that we have migrations in place for certain keys in
PersistenceService. When possible, add variables to the migration mechanism to make sure data isn't lost midway. Not all changes necessitate migrations - for example,login_statecan be replaced without a migration as it will simply prompt users to log back in.However, some data is synced with the backend (either selfhosted or cloud):
These synchronized items definitely need migrations to ensure users don't lose their data, and we've provided those migrations in the service.
Note to Reviewers
There still exist sync calls to
PersistenceServicemethods, especially instd/interceptors,sh-desktop/platformand similar legacy modules. Although these modules are not directly in use anymore, there may exist some static function calls that may be used by live modules indirectly, even though they don't depend on the kernel.These modules are up for removal upon ongoing evaluation, so any
PersistenceServicein these modules can be safely ignored.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.