Skip to content

Commit fe1e4c3

Browse files
authored
Merge pull request #8161 from marmelab/fix-store-removeitems
Fix localStorageStore.reset() does not remove all items
2 parents c7b2279 + 74ce76a commit fe1e4c3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

packages/ra-core/src/store/localStorageStore.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,13 @@ export const localStorageStore = (
116116
},
117117
reset(): void {
118118
const storage = getStorage();
119-
for (let i = 0; i < storage.length; i++) {
120-
if (storage.key(i)?.substring(0, prefixLength) === prefix) {
121-
const key = storage.key(i)?.substring(prefixLength + 1);
122-
if (!key || !storage.key(i)) return;
123-
// @ts-ignore
124-
storage.removeItem(storage.key(i));
125-
publish(key, undefined);
119+
Object.keys(storage).forEach(key => {
120+
if (key.startsWith(prefix)) {
121+
storage.removeItem(key);
122+
const publishKey = key.substring(prefixLength + 1);
123+
publish(publishKey, undefined);
126124
}
127-
}
125+
});
128126
},
129127
subscribe: (key: string, callback: (value: string) => void) => {
130128
const id = Math.random().toString();

0 commit comments

Comments
 (0)