i18next / i18next-localstorage-backend

This is a i18next cache layer to be used in the browser. It will load and cache resources from localStorage and can be used in combination with the chained backend.
MIT License
88 stars 43 forks source link

empty string as default version breaks expiry validation #18

Closed ljosberinn closed 4 years ago

ljosberinn commented 4 years ago

Hi,

noticed that my geti18n endpoint receives requests although its data is definitely already stored. Providing defaultVersion: anyString fixed it.

https://github.com/i18next/i18next-localstorage-backend/blob/master/src/index.js#L33 ensures the default version is an empty string

https://github.com/i18next/i18next-localstorage-backend/blob/master/src/index.js#L85 falls back to the defaultValue if none was provided for the current language right after, it checks whether a version was found and only then sets it - '' is falsy though, so the value won't get set

https://github.com/i18next/i18next-localstorage-backend/blob/master/src/index.js#L69 which leads to this always being false, leading to a permanent refetch

proposed solutions:

Both sound kinda stupid to me right now, but that's because I've been debugging this for an hour and now its past 4 am. :sweat_smile: I can create a PR later.

jamuhl commented 4 years ago

👍PR welcome....@slevy85 you might also look into this?

slevy85 commented 4 years ago

I am sorry for this I introduced a regression, the problem is version === local.i18nVersion compares empty string with undefined, with double equals it would workd but a better solution is to intialize defaultVersion to undefined.