Skip to content

[charts] TypeError: useSyncExternalStore is not a function when using @mui/x-charts with React 17 #18303

@tomashlavac

Description

@tomashlavac

Steps to reproduce

Steps:

  1. Create a React 17 application
  2. Install MUI X Charts: yarn add @mui/x-charts-pro
  3. Create a simple component using MUI X Charts (e.g., a BarChart)
  4. Attempt to render the component

Code Sandbox:
https://codesandbox.io/p/sandbox/gn44dg

Current behavior

The component fails to render with the error TypeError: useSyncExternalStore is not a function. This is because useSyncExternalStore was introduced in React 18, but the library is attempting to use it without providing a polyfill for React 17.

Uncaught TypeError: useSyncExternalStore is not a function
    at exports.useSyncExternalStoreWithSelector (@mui_x-charts-pro.js?v=099e1ff7:170:21)
    at useSelector (@mui_x-charts-pro.js?v=099e1ff7:1574:68)
    at useChartDimensions (@mui_x-charts-pro.js?v=099e1ff7:1788:23)
    at runPlugin (@mui_x-charts-pro.js?v=099e1ff7:2124:28)
    at Array.forEach (<anonymous>)
    at useCharts (@mui_x-charts-pro.js?v=099e1ff7:2140:11)
    at ChartProvider (@mui_x-charts-pro.js?v=099e1ff7:9022:7)
    at renderWithHooks (chunk-GTDYCZLZ.js?v=3f29c4e8:10693:26)
    at mountIndeterminateComponent (chunk-GTDYCZLZ.js?v=3f29c4e8:12869:21)
    at beginWork (chunk-GTDYCZLZ.js?v=3f29c4e8:13698:22)

Expected behavior

The chart component should render without errors since React 17 is listed as a compatible peer dependency:

"peerDependencies": {
  "react": "^17.0.0 || ^18.0.0 || ^19.0.0",
  "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
}

Context

No response

Your environment

npx @mui/envinfo
  System:
    OS: macOS 15.2
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 10.11.0 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 137.0.7151.69
    Edge: Not Found
    Safari: 18.2

Order ID or Support key 💳 (optional):
99326

Search keywords: React 17 compatibility, useSyncExternalStore, MUI X Charts, TypeError, peer dependencies, polyfill, use-sync-external-store shim, React version support, bundle compatibility, Storybook integration, Charts rendering, React 17 shim, dependency resolution, compatibility layer, React hooks, MUI X components

Metadata

Metadata

Labels

scope: chartsChanges related to the charts.scope: tree viewChanges related to the tree view. This includes TreeView, TreeItem.type: bugIt doesn't behave as expected.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions