You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What you were expecting:
localStorageStore accepting a numeric value as stated in documentation What happened instead:
Using a numeric value (eg:0) causes store invalidation. The store invalidation calls localStorage.clean that wipe also other data that maybe are unrelated directly with react admin.
import { Admin, Resource, localStorageStore } from 'react-admin';
const STORE_VERSION = 2; //<-- this is wrong!
const App = () => (
<Admin dataProvider={dataProvider} store={localStorageStore(STORE_VERSION)}>
<Resource name="posts" />
</Admin>
);
so, because on LocalStorageStore.ts you check if (storedVersion && storedVersion !== version) {
this is inconsistent because you are saving storedVersion on localStorage as a string, but version in memory is numeric.
note that the session will be invalidated if you refresh the page.
as you declared in localStorageStore.d.ts: export declare const localStorageStore: (version?: string, appKey?: string) => Store;
With typescript this should trigger a type mismatch
my conclusions are:
the documentation is wrong ( STORE_VERSION should be "2" instead of 2) and this is the original problem
i also want to suggest that you should not clean all the localStorage, (by calling localStorage.clean() ) on version verify, but maybe i can suggest to add a prefix to RaStore variables to clean (for example, "RaStore.myVariable" or "RaStore.2.myVariable") because you cannot be sure that the localStorage doesn't have some custom logic values (as my case) that needs to be preserved 👨🔧
Thank you as usual for your great work 🙏
React-admin version: 4.4.4
Last version that did not exhibit the issue (if applicable):
React version: not related
Browser: Chrome
Stack trace (in case of a JS error):
The text was updated successfully, but these errors were encountered:
You're right. Would you like to open a PR to fix the doc?
You're also right. We are indeed using a prefix, so on version change, we should find all keys with that prefix and delete only these one (kind of like what we do in removeItems). Would you like to work on a second PR for this?
What you were expecting:
localStorageStore accepting a numeric value as stated in documentation
What happened instead:
Using a numeric value (eg:0) causes store invalidation. The store invalidation calls localStorage.clean that wipe also other data that maybe are unrelated directly with react admin.
Steps to reproduce:
https://github.com/marmelab/react-admin/blob/master/docs/Store.md
so, because on LocalStorageStore.ts you check
if (storedVersion && storedVersion !== version) {
this is inconsistent because you are saving storedVersion on localStorage as a string, but version in memory is numeric.
note that the session will be invalidated if you refresh the page.
as you declared in localStorageStore.d.ts:
export declare const localStorageStore: (version?: string, appKey?: string) => Store;
With typescript this should trigger a type mismatch
my conclusions are:
Thank you as usual for your great work 🙏
The text was updated successfully, but these errors were encountered: