localForage / localForage/localForage-sessionStorageWrapper
clear() does not work as intended
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 20
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/localForage/localForage-sessionStorageWrapper/blob/8edfa0cd523eed5497c29a22495d4dd8a6e5839c/lib/index.ts#L77-L83) 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()`](https://developer.mozilla.org/en-US/docs/Web/API/Storage/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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/index.ts at clear() (lines 77-83) and reproduce the case with an unrelated sessionStorage key alongside prefixed keys. Make completion independent of key-order changes during removal, then verify that every prefixed key is removed while the unrelated key remains.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100