Skip to content

AdapterDayjs - excessive invocations of dayjs.locale() method #18410

Open
@paal-havnevik-jobbkretser

Description

Steps to reproduce

Steps:

  1. clone the mui-x repo (this repo)
  2. run pnpm i
  3. replace file /packages/x-date-pickers/node_modules/dayjs/dayjs.min.js with the attached file dayjs.min.js.txt (remove the .txt extension). The attached file extends the dayjs parseLocale()method with aconsole.log('dayjs.parseLocale invoked');` call.
  4. run pnpm start
  5. browse to http://localhost:3001/x/react-date-pickers/date-picker/ with Chrome Dev tools open
  6. observe ~20.000 console log entries: dayjs.parseLocale invoked

Modified dayjs.min.js.txt:

dayjs.min.js.txt

Current behavior

The documentation page (http://localhost:3001/x/react-date-pickers/date-picker/) will invoke the dayjs.locale() (internally named parseLocale in dayjs) method some 20.000 times upon initial page load.

Selecting dates in the picker increases the amount of calls quickly.

Expected behavior

Fewer calls to dayjs.locale().

Context

I stumbled upon this when debugging why the given i18n locale from ThemeProvider was ignored in only parts of the date picker "Mobile" view: the date and day name in the picker header was not translated, but the months list and action buttons were.

Your environment

npx @mui/envinfo

System:
OS: Windows 10 10.0.19045
Binaries:
Node: 22.16.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.12.1 - ~\AppData\Roaming\npm\pnpm.CMD
Browsers:
Chrome: 137.0.7151.104
Edge: Chromium (137.0.3296.83)
npmPackages:
@emotion/react: catalog: => 11.14.0
@emotion/styled: catalog: => 11.14.0
@mui/icons-material: catalog: => 7.1.1
@mui/internal-babel-plugin-display-name: ^1.0.1 => 1.0.1
@mui/internal-babel-plugin-resolve-imports: ^2.0.4 => 2.0.4
@mui/internal-bundle-size-checker: ^1.0.5 => 1.0.5
@mui/internal-markdown: ^2.0.6 => 2.0.6
@mui/internal-test-utils: catalog: => 2.0.9
@mui/material: catalog: => 7.1.1
@mui/monorepo: github:mui/material-ui#29efc5bbdfe28d944c754d5be4a1c2761ec34f7a => 7.1.1
@mui/utils: catalog: => 7.1.1
@types/react: catalog: => 19.0.12
react: catalog: => 19.0.0
react-dom: catalog: => 19.0.0
typescript: ^5.8.3 => 5.8.3

Search keywords: adapterdayjs dayjs

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions