Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError Cannot read properties of null (reading 'getItem') #297

Open
m-nathani opened this issue Feb 14, 2025 · 3 comments
Open

TypeError Cannot read properties of null (reading 'getItem') #297

m-nathani opened this issue Feb 14, 2025 · 3 comments

Comments

@m-nathani
Copy link

🐛 Bug Report

App is breaking because of this bug,., we got an Typeerror exception raised in our sentry logs as attached in the screenshot below

Image

To Reproduce

Here is the public link with trace of this error :
https://umai.sentry.io/share/issue/ab6e3304bc0e4c42a4737828c7d35a41/

../node_modules/.pnpm/[email protected]/node_modules/i18next-browser-languagedetector/dist/esm/i18nextBrowserLanguageDetector.js in localStorage.lookup at line 174:34

    if (lookupLocalStorage && localStorageAvailable()) {
      return window.localStorage.getItem(lookupLocalStorage) || undefined; // Undefined ensures type consistency with the previous version o {snip}    <------------------------ this line.
    }

Expected behavior

Not to have this error and handle window location api with checks

Currently getting : TypeErrorCannot read properties of null (reading 'getItem')

Your Environment

  • runtime version: node 22
  • i18next version: "i18next": "^23.16.5", "i18next-browser-languagedetector": "^8.0.0", "react-i18next": "^15.1.1",
  • os: Linux
@adrai
Copy link
Member

adrai commented Feb 14, 2025

How does your i18next config look like? Are you setting the lookupLocalStorage option to null?
Nevertheless, v8.0.3 should address this.

@danielrentz
Copy link
Contributor

danielrentz commented Feb 21, 2025

@adrai I checked the code again, and the only idea I came up with how this could happen is, that there may be different window objects in the same script environment, one with localStorage, and another without (private browser tab, maybe in some test environment?). That could indeed bypass checking the existence of "localStorage" if it has been checked once before with the complete window.

An idea to fix this would be to create a Map<Window, boolean> that stores the check results per window instance. If you like, I would prepare another PR for this.

@adrai
Copy link
Member

adrai commented Feb 21, 2025

Ii really would love to have a reproducible example first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants