Problem
Running tools clarity ui crashes during SSR with:
TypeError: null is not an object (evaluating 'resolveDispatcher().useState')
at Toaster (node_modules/sonner/dist/index.mjs:1065:21)
Root Cause
Dual React instance during server-side rendering:
sonner was only declared in the root package.json → installed in root node_modules/ → imports root react (v19.2.0)
- The clarity UI app has its own
node_modules/react (v19.2.4) and react-dom (v19.2.4)
- During SSR,
react-dom-server sets up its internal dispatcher on the local react instance
- When
sonner's <Toaster> calls useState, it goes through the root react instance which has no dispatcher → resolveDispatcher() returns null → crash
Fix
Add sonner to src/clarity/ui/package.json dependencies so it resolves through the local node_modules/ and uses the same react instance as the rest of the app.
# src/clarity/ui/package.json
"lucide-react": "^0.544.0",
"react": "^19.2.1",
+ "sonner": "^2.0.7",
"react-dom": "^19.2.1",
Then bun install in src/clarity/ui/.
Verification
After the fix, both the app and sonner resolve to the same react:
sonner → src/clarity/ui/node_modules/react/index.js
app → src/clarity/ui/node_modules/react/index.js
Note
Any package that uses React hooks and is only in the root node_modules/ (not the dashboard's local node_modules/) will hit the same issue during SSR. Dashboard apps with their own node_modules/react must declare all React-dependent packages locally.
Problem
Running
tools clarity uicrashes during SSR with:Root Cause
Dual React instance during server-side rendering:
sonnerwas only declared in the rootpackage.json→ installed in rootnode_modules/→ imports rootreact(v19.2.0)node_modules/react(v19.2.4) andreact-dom(v19.2.4)react-dom-serversets up its internal dispatcher on the local react instancesonner's<Toaster>callsuseState, it goes through the root react instance which has no dispatcher →resolveDispatcher()returnsnull→ crashFix
Add
sonnertosrc/clarity/ui/package.jsondependencies so it resolves through the localnode_modules/and uses the same react instance as the rest of the app.Then
bun installinsrc/clarity/ui/.Verification
After the fix, both the app and sonner resolve to the same react:
Note
Any package that uses React hooks and is only in the root
node_modules/(not the dashboard's localnode_modules/) will hit the same issue during SSR. Dashboard apps with their ownnode_modules/reactmust declare all React-dependent packages locally.