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

Intermittent RangeError: Incorrect locale information provided in i18next.getLocale(request) #209

Closed
kenn opened this issue Sep 3, 2024 · 2 comments

Comments

@kenn
Copy link

kenn commented Sep 3, 2024

Describe the bug

From time to time, I'm getting the following error at this line: let lng = await i18next.getLocale(request)

I have no idea how to debug this, let me know if you want me to set something up to debug the issue.

RangeError: Incorrect locale information provided
    at Function.supportedLocalesOf (<anonymous>)
    at getClientLocales

Here's a screenshot from Sentry:

Screenshot 2024-09-03 at 19 12 44

Your Example Website or App

https://gista.co/

Steps to Reproduce the Bug or Issue

Set up as README along with i18n.ts configured as follows:

export default {
  supportedLngs: ['en', 'ja'],
  fallbackLng: 'en',
  defaultNS: 'common',
  react: { useSuspense: false },
}

Expected behavior

No error

Screenshots or Videos

No response

Platform

From Sentry:

Screenshot 2024-09-03 at 19 10 12

Additional context

No response

@jansedlon
Copy link
Contributor

jansedlon commented Sep 16, 2024

I think it relates to my issue #207 because apart from my error, it shows me the same error as yours

@jansedlon
Copy link
Contributor

jansedlon commented Sep 17, 2024

@kenn I have made a PR that should fix it #211

sergiodxa pushed a commit that referenced this issue Sep 17, 2024
…cale (#211)

Hi, following up on my #207 and someones #209. 

This PR consists of two changes.

## Filter out invalid locales instead of throwing exceptions

I have MANY thrown exception in Sentry from my users. Sometimes it's
just bots, sometimes it's a weird combination of environment and
browsers. However sometimes a request i received contains an invalid
locale (see tests, there are real world `Accept-Language` headers). In
my opinion it's better to gracefully filter out one of the invalid
locales instead of throwing an exception
(`Intl.DateTimeFormat.supportedLocalesOf` does that)

## Better handling of whitespaces
Even though you have tests for random whitespaces, it doesn't handle all
the cases as i have observed. The
[specification](https://datatracker.ietf.org/doc/html/rfc3282#section-3)
specifies multiple places where whitespaces can occur, i have handled
the additional whitespaces and also made a test from one of my Sentry
errors that bypassed your test.
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