-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Description
Describe the bug
@tanstack/query-devtools throws at runtime when navigator.language is an invalid string such as "undefined".
The published package still derives the locale from:
(navigator.language || navigator.userLanguage) || "en-US"If a browser/runtime reports navigator.language === "undefined" instead of undefined, that value reaches locale-sensitive logic and causes a RangeError.
I reproduced this with a minimal React app that mounts ReactQueryDevtools after forcing:
navigator.language = "undefined"
navigator.languages = ["undefined"]
navigator.userLanguage = "undefined"Your minimal, reproducible example
https://github.com/jakvbs/query-devtools-locale-repro
Steps to reproduce
- Install the repro dependencies
- Run the app
- Open it in Firefox or Chromium
- The app forces
navigator.languageto the string"undefined"before mountingReactQueryDevtools - Observe a runtime
RangeError
Expected behavior
Devtools should sanitize invalid locale values and fall back safely to "en-US" instead of throwing.
How often does this bug happen?
Every time
Screenshots or Videos
Firefox:
RangeError: invalid language tag: "undefined"
at mount/dispose< (.../@tanstack_react-query-devtools.js:111:14)
Chromium:
RangeError: Incorrect locale information provided
at getDefaultLocale (.../chunk-*.js:2496:16)
The wording differs by browser, but the root cause is the same invalid locale path.
Platform
- OS: Linux
- Browsers:
- Firefox 146.0
- Chromium (Playwright-installed Chromium)
TanStack Query adapter
react-query
TanStack Query version
Repro app:
@tanstack/react-query:5.90.20@tanstack/react-query-devtools:5.91.3
I also inspected published @tanstack/query-devtools tarballs for:
5.91.15.92.05.93.0
All three still contain:
function getDefaultLocale() {
let locale = typeof navigator !== "undefined" &&
(navigator.language || navigator.userLanguage) || "en-US";TypeScript version
Not relevant for this runtime bug
Additional context
This reproduces in both Firefox and Chromium.
One thing that made this confusing is that a quick search in the current source tree does not obviously show getDefaultLocale, because that logic comes from bundled dependency code in the published @tanstack/query-devtools artifact rather than a handwritten source file in this repo.
The devtools source also has direct locale-sensitive toLocaleString() call sites, so the invalid locale can surface through more than one runtime path.