question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next.JS SSR: dispatcher.useInsertionEffect is not a function

See original GitHub issue

What package has an issue

@mantine/core

Describe the bug

When using @mantine/core popover, or any of its siblings (Menu.Dropdown or Tooltip), with Next.JS SSR (Server side rendering), and exception is thrown:

error - TypeError: dispatcher.useInsertionEffect is not a function at useInsertionEffect (/Users/USER/Development/sandbox/PROJECT/node_modules/react/cjs/react.development.js:1638:21) at useEvent (/Users/USER/Development/sandbox/PROJECT/node_modules/@floating-ui/react-dom-interactions/dist/floating-ui.react-dom-interactions.umd.js:186:7) at Object.useFloating (/Users/USER/Development/sandbox/PROJECT/node_modules/@floating-ui/react-dom-interactions/dist/floating-ui.react-dom-interactions.umd.js:223:26) at Object.usePopover (/Users/USER/Development/sandbox/PROJECT/node_modules/@mantine/core/cjs/Popover/use-popover.js:45:41) at Popover (/Users/USER/Development/sandbox/PROJECT/node_modules/@mantine/core/cjs/Popover/Popover.js:127:30) at renderWithHooks (/Users/USER/Development/sandbox/PROJECT/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:454:15) at render$2 (/Users/USER/Development/sandbox/PROJECT/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:465:6) at /Users/USER/Development/sandbox/PROJECT/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:612:12 at render (/Users/USER/Development/sandbox/PROJECT/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:613:4) at visitElement (/Users/USER/Development/sandbox/PROJECT/node_modules/react-ssr-prepass/dist/react-ssr-prepass.js:725:15) { page: ‘/projects/[id]’ }

This only happens if doing SSR, and not if the component is rendered client side. It is possible to workaround this, by simply not rendering the component until client side hydration, for example:

{typeof window !== "undefined" && (
  <Tooltip label="My tooltip">
    <div>Hover me</div>
  </Tooltip>
)}

However this gives a server/client mismatch.

My initial guess would be, that the @floating-ui package is looking for a ref, thats not yet created due to SSR.

What version of @mantine/hooks page do you have in package.json?

5.5.0

If possible, please include a link to a codesandbox with the reproduced problem

No response

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

Yes

Possible fix

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
MirSowasVonEgalcommented, Oct 16, 2022

Hello,

I have the same problem, but unfortunately haven’t found a solution yet.

I’ll report when I’ve solved the problem.

0reactions
viczamcommented, Oct 31, 2022

@jimmyruann Hm, the codesandbox example has the same issue (I also followed the template from here - https://github.com/mantinedev/mantine-next-template). But I’ve done some thinking and as much as I like the convenience of trpc with ssr: true, it’s not the best idea. I will prefetch the queries in getServerSideProps / getStaticProps whenever needed, and that works fine with mantine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react select error on upgrade: TypeError: dispatcher ...
I solved it by removing the HMR completely from webpack.config.js. Hope it helps. Share.
Read more >
Uncaught TypeError: dispatcher.useInsertionEffect is not a ...
Describe the bug I'm created a project using rollup the project is basically a library out of which I'm exporting some reusable componnents....
Read more >
TypeError: dispatcher.useInsertionEffect is not a function-Reactjs
Coding example for the question react select error on upgrade: TypeError: dispatcher.useInsertionEffect is not a function-Reactjs.
Read more >
Data Fetching: getServerSideProps - Next.js
Note that you must export getServerSideProps as a standalone function — it will not work if you add getServerSideProps as a property of...
Read more >
Exploring React 18's three new APIs - LogRocket Blog
The useInsertionEffect Hook. Issues with CSS-in-JS libraries. The last Hook that will be added in React 18 — and that we'll discuss here ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found