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

Using ThemeSwitcher alone fails with "Cannot read properties of null (reading 'useSyncExternalStore')" #4635

Open
ebengtso opened this issue Jan 24, 2025 · 4 comments
Labels
status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@ebengtso
Copy link

ebengtso commented Jan 24, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: (required)
  2. In the first customisation example, the ThemeSwitcher does not work
  3. I tried locally, I I have this issue:

TypeError: Cannot read properties of null (reading 'useSyncExternalStore') at exports.useSyncExternalStore (/myfolder/node_modules/@toolpad/utils/node_modules/react/cjs/react.production.js:529:33) at useSsr (/myfolder/node_modules/@toolpad/utils/dist/hooks/useSsr.cjs:48:16) at ThemeSwitcher (/myfolder/node_modules/@toolpad/core/node/DashboardLayout/ThemeSwitcher.js:32:37) at Wc (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44) at Zc (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253) at Z (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89) at $c (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98) at bd (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404) at Z (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217) at Zc (/myfolder/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:479)

Current behavior

No response

Expected behavior

No response

Context

No response

Your environment

nextjs 14 (latest) latest Toolpad code and mui react 18 (latest)

Search keywords: ThemeSwitcher

@ebengtso ebengtso added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 24, 2025
@bharatkashyap
Copy link
Member

  1. Open this link to live example: (required)
  2. In the first customisation example, the ThemeSwitcher does not work
  3. I tried locally, I I have this issue:

The theme switcher works for each demo in the docs for me; can you provide a reproduction CodeSandbox or StackBlitz link for us to be able to check this?

@bharatkashyap bharatkashyap added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 27, 2025
@bringmetheaugust
Copy link

have the same problem using DashboardLayout

TypeError: Cannot read properties of null (reading 'useSyncExternalStore')
    at exports.useSyncExternalStore (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-5KE5NN7T.js?v=c3c9b094:1174:35)
    at useSsr (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-X4VEM7D7.js?v=c3c9b094:795:17)
    at ThemeSwitcher (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-X4VEM7D7.js?v=c3c9b094:803:17)
    at renderWithHooks (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:11548:26)
    at mountIndeterminateComponent (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:14926:21)
    at beginWork (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:15914:22)
    at beginWork$1 (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:19753:22)
    at performUnitOfWork (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:19198:20)
    at workLoopSync (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:19137:13)
    at renderRootSync (http://adm.leprechaun.loc/node_modules/.vite/deps/chunk-PBXWVHXV.js?v=c3c9b094:19116:15)

@bringmetheaugust
Copy link

Hmm. I've set the same dependency versions as in the docs example and now it works.

Also I missed "@vitejs/plugin-react" dependency. Maybe it caused the problem. idk

@ebengtso
Copy link
Author

To reproduce the issue, you can use the code in the sandbox from the doc, and update the dependencies of react to version 18.3.1, according the below code

I listed Toolpad dependencies and it seems that it requires react 19. Is this on purpose?

├─┬ @toolpad/[email protected]
│ │ └── [email protected]

The package.json updating the docs sample to reproduce the issue:
{ "dependencies": { "@emotion/react": "latest", "@emotion/styled": "latest", "@mui/icons-material": "latest", "@mui/material": "latest", "@toolpad/core": "latest", "@types/invariant": "latest", "@types/react": "18.3.1", "@types/react-dom": "18.3.1", "invariant": "latest", "react": "18.3.1", "react-dom": "18.3.1", "typescript": "latest" }, "description": "https://github.com/mui/toolpad/blob/v0.12.0/docs/data/toolpad/core/components/dashboard-layout/DashboardLayoutSlots.tsx", "devDependencies": { "react-scripts": "latest" }, "main": "index.tsx", "scripts": { "build": "react-scripts build", "eject": "react-scripts eject", "start": "react-scripts start", "test": "react-scripts test" } }

Thanks

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants