Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear() does not work as intended #14

Open
jhnns opened this issue Jun 28, 2021 · 0 comments
Open

clear() does not work as intended #14

jhnns opened this issue Jun 28, 2021 · 0 comments

Comments

@jhnns
Copy link

jhnns commented Jun 28, 2021

Hi 馃憢,

first of all: thanks for this library 鉂わ笍

I noticed that clear() does not always remove all keys. This happens when there's another key in the SessionStorage that does not have the store prefix (in my case it was a browser extension).

The current implementation iterates over all keys and removes them if they have the store prefix. The remove operation, however, might mess with the order of keys that are returned by key(i). In my case, key(i) returned the same key for a different i. MDN writes about key():

The order of keys is user-agent defined, so you should not rely on it.

The current implementation can be fixed by first getting all the keys via Object.keys() and then iterating over that array. Object.keys() has good browser support these days but I don't know if that's ok for you. You could also iterate with for ... in.

Are you interested in a fix with Object.keys()? I could send a 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

No branches or pull requests

1 participant