What happened?
If one sets the storage option as sessionStorage in localoptions object it will be ignored and localStorage will be used instead.
Example:
ls.set("testItem", "123", {storage: sessionStorage});
It will save testItem
in localStorage and not in sessionStorage. It can be observed on browser dev tools.
Also, when retrieving data, the library also ignores the storage option:
ls.get("testItem", {storage: sessionStorage});
It will retrieve the object not only in sessionStorage but also in localStorage. Not sure if the last behavior is intended though.
I provided a codepen project that shows both local and session behavior.
Affected version
v2.7.0
Reproduction URL
https://codepen.io/gurgelff/pen/OJdoyxr
How to reproduce?
1 - Go to the provided codepen link
2 - Write some value in input field, like 123 (the code is already set to use sessionStorage in localconfig object).
3 - Notice that "Get from sessionStorage (native API):" returns nothing from SessionStorage.
4 - Notice also that both session and local storage using the library return some values, even though the saved value is only present in session, and not in localStorage.
Browsers
Firefox, Brave
Relevant log output
No response
Additional context
On Codepen, when using global config the issue seems resolved. But a localconfig scope is something useful that needs to be solved.
There is also an issue when used in Angular, that even with a global config it still doesn't use sessionStorage, but that is a matter for another issue.