{"record":{"id":"821245f572698747","repo":"marmelab/react-admin","slug":"failed-to-execute-key-on-storage-1-argument-r","errorCode":null,"errorMessage":"Failed to execute 'key' on 'Storage': 1 argument required, but only 0 present.","messagePattern":"Failed to execute 'key' on 'Storage': 1 argument required, but only 0 present\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/ra-core/src/store/localStorageStore.ts","lineNumber":211,"sourceCode":"    removeItem(key: string) {\n        this.valuesMap.delete(key);\n    }\n\n    removeItems(keyPrefix: string) {\n        this.valuesMap.forEach((value, key) => {\n            if (key.startsWith(keyPrefix)) {\n                this.valuesMap.delete(key);\n            }\n        });\n    }\n\n    clear() {\n        this.valuesMap.clear();\n    }\n\n    key(i): string {\n        if (arguments.length === 0) {\n            throw new TypeError(\n                \"Failed to execute 'key' on 'Storage': 1 argument required, but only 0 present.\"\n            ); // this is a TypeError implemented on Chrome, Firefox throws Not enough arguments to Storage.key.\n        }\n        const arr = Array.from(this.valuesMap.keys()) as string[];\n        return arr[i];\n    }\n\n    get length() {\n        return this.valuesMap.size;\n    }\n}\nconst memoryStorage = new LocalStorageShim();\n\nexport const getStorage = () => {\n    return localStorageAvailable ? window.localStorage : memoryStorage;\n};\n","sourceCodeStart":193,"sourceCodeEnd":228,"githubUrl":"https://github.com/marmelab/react-admin/blob/051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0/packages/ra-core/src/store/localStorageStore.ts#L193-L228","documentation":"react-admin's localStorageStore includes a localStorage-compatible InMemoryStorage shim. Its key(i) method mimics the Web Storage API, which requires exactly one argument, so it throws a TypeError when called with zero arguments — matching Chrome's native behavior so code that expects the platform error behaves the same in memory-only environments (SSR, tests, private-mode fallbacks).","triggerScenarios":"Calling localStorageStore.key() with no argument (or spreading an empty argument list) into the store object returned when window.localStorage is unavailable; generic code iterating Storage keys that omits the index on first iteration.","commonSituations":"SSR/test environments where window.localStorage is undefined so the in-memory shim is used; browser privacy mode fallbacks; porting code that worked with native Storage error messages and relying on the Chrome-style TypeError text.","solutions":["Always pass an index: store.key(0), store.key(1), ... and stop when the result is null.","Guard before calling: if (i !== undefined) store.key(i).","If you need all keys, iterate with key(i) from i=0 while non-null instead of calling key() without arguments."],"exampleFix":"// before\nconst firstKey = localStorageStore.key(); // TypeError\n\n// after\nconst firstKey = localStorageStore.key(0); // may be null if empty","handlingStrategy":"type-guard","validationCode":"if (typeof index === 'undefined') {\n    throw new Error('Storage.key requires an index');\n}\nconst key = store.key(index);","typeGuard":"const hasIndex = (i: number | undefined): i is number => typeof i === 'number' && i >= 0;","tryCatchPattern":"try {\n    key = store.key(i);\n} catch (e) {\n    if (e instanceof TypeError) console.error('key() requires an index');\n    key = null;\n}","preventionTips":["Always call key() with an explicit integer index.","Iterate keys with a while (store.key(i) !== null) loop from i=0.","Mirror Web Storage API signatures when wrapping the store."],"tags":["storage","typeerror","argument-error","ssr"],"backgroundTag":"missing-required-argument","analyzedSha":"051f511bb0afb5ea565c2d3728bf4dab0a6fa5e0","analyzedAt":"2026-08-30T02:28:14.926Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}