Daydreamer-riri / vite-react-ssg

Static-site generation for React on Vite.
https://vite-react-ssg.netlify.app/
MIT License
127 stars 6 forks source link

Issue with components library : Cannot read properties of null (reading 'registered') #27

Closed stouch closed 7 hours ago

stouch commented 2 months ago

I'm using a components library with @emotion/styled components (MUI components). I don't use any emotion cache.

As I understood it, it looks like vite-react-ssg prerender components server-side, and so I got this error because of this :

[vite-react-ssg] error: TypeError: Cannot read properties of null (reading 'registered')
    at file:///Users/<COMPONENT_LIBRARY>/dist/react-uikit.js:3258:49
    at file:///Users/<COMPONENT_LIBRARY>/dist/react-uikit.js:3174:12
    at renderWithHooks (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:5724:16)
    at renderForwardRef (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:5919:18)
    at renderElement (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:6082:11)
    at renderNodeDestructiveImpl (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:6181:11)
    at renderNodeDestructive (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:6153:14)
    at renderForwardRef (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:5936:5)
    at renderElement (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:6082:11)
    at renderNodeDestructiveImpl (/<MY_PROJECT_PATH>/node_modules/react-dom/cjs/react-dom-server.node.development.js:6181:11)

If i dig into the lines :

Capture d’écran 2024-09-01 à 11 25 51 Capture d’écran 2024-09-01 à 11 26 31

Any ideas ?

(I already tried to set @emotion/styled as a peerDep in my components library, and dedupe it in the vite.config of my project).

An "ugly" solution :

I succeeded to fix this by using <ClientOnly> in my project around my library components, but this look quite ugly.

Daydreamer-riri commented 2 months ago

Can you provide a minimum reproduction repository?