Data Binding causing React Hydration Mismatch errors

I have a custom component that is a card to display data from a section on a landing page. If I populate the data in the card on a page directly in the page editor it works fine. However I am displaying 8+ of these cards in a flex box so I really want to use a databinding to a query of the practice sections. As soon as i create the binding either thru a query or even just to one record it starts generating a hydration mismatch. Here is a video of the error:

Recording-20240731_200431.webm

Here is the code behind the custom component:

import Image from "next/image";
import Link from "next/link";
import { useState } from "react"; // Add missing import

function PracticeCard(props) {
  const { name, title, thumbnail, altText } = props;
  const [isHovered, setIsHovered] = useState(false); // Add missing state variable and useState hook

  let imageValue = thumbnail?.length > 0 ? thumbnail : '/images/primary-care2.png';
  let titleValue = title || 'Sample Practice';
  let nameValue = name || 'sample-practice'; 

  return (
    <div className="flex h-80 w-72 xl:w-80">
      <div id="image">
        <img src={imageValue} alt={altText} className="h-60 w-full" />
      </div>
      <div
        id="overlay"
        className={`absolute bottom-0 ${isHovered ? 'h-1/3' : 'h-1/4'} w-72 xl:w-80  bg-primaryAccent hover:bg-secondaryAccent group`}
        // onMouseEnter={() => setIsHovered(true)}
        // onMouseLeave={() => setIsHovered(false)}
      >
        <div className="flex mx-auto">
          <h3 className="text-primaryLight group-hover:text-primaryDark mx-auto px-4">
            <a className="text-primaryLight" href={`/practices/${nameValue}`}>{titleValue}</a>
          </h3>
        </div>
      </div>
    </div>
  );
}

export default PracticeCard;

FInally, here is a link to the github project for my site:

And the public key to my space is:
21c8ab133cb64454a96650df9ce1d9e5

Here is a link the page showing the problem:

Hello @jhs129,

We suspect the issue might be caused by the isolate-vm dependency not working when running the server locally. Are you seeing any warnings in the IDE console related to ‘isolate-vm’?

Skipping usage of `isolated-vm` to avoid crashes in Node v20 on an arm64 machine.
    If you would like to use the `isolated-vm` package on this machine, please provide the `NODE_OPTIONS=--no-node-snapshot` config to your Node process.
    See https://github.com/BuilderIO/builder/blob/main/packages/react/README.md#node-v20--m1-macs-apple-silicon-support for more information.

I resolved the hydration error by passing ‘NODE_OPTIONS=–no-node-snapshot’ param with the command that runs the local server.

i.e.,

  "scripts": {
    "dev": "NODE_OPTIONS=--no-node-snapshot next dev",
    "build": "NODE_OPTIONS=--no-node-snapshot next build",
    "start": "NODE_OPTIONS=--no-node-snapshot next start",
    "lint": "next lint"
  },


Thanks Manish! That doesn’t seem to be the issue as I made those changes and I am still getting the error:

Here is the output when I run the node server:

orh-poc@0.1.0 dev

NODE_OPTIONS=–no-node-snapshot next dev

▲ Next.js 14.1.1

✓ Ready in 1113ms
○ Compiling /[…page] …
✓ Compiled /[…page] in 1575ms (419 modules)
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
Warning: React does not recognize the _newProperty prop on a DOM element. If you intentionally want it to appear in the DOM as a custom attribute, spell it as lowercase _newproperty instead. If you accidentally passed it from a parent component, remove it from the DOM element.
at div
at BuilderBlock (/Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:13220)
at div
at section
at CardSection (webpack-internal:///./components/ui/card-section.jsx:17:37)
at s (/Users/johnhschneider/dev/orh-hackathon/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:8:2941)
at /Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:62364
at div
at BuilderBlock (/Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:13220)
at div
at BasicProvider (/Users/johnhschneider/dev/orh-hackathon/node_modules/@emotion/core/dist/emotion-element-c423a2c0.cjs.dev.js:45:32)
at EmotionCssPropInternal
at t (/Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:22212)
at div
at div
at VariantsProvider (/Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:27438)
at BuilderContent (/Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:28565)
at div
at t (/Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react/dist/builder-react.cjs.js:1:41391)
at Page (webpack-internal:///./pages/[…page].jsx:84:17)
at HydrationOverlay (file:///Users/johnhschneider/dev/orh-hackathon/node_modules/@builder.io/react-hydration-overlay/dist/HydrationOverlay.mjs:4:29)
at App (webpack-internal:///./pages/_app.jsx:19:16)
at StyleRegistry (/Users/johnhschneider/dev/orh-hackathon/node_modules/styled-jsx/dist/index/index.js:449:36)
at eV (/Users/johnhschneider/dev/orh-hackathon/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:8:22622)
at eO (/Users/johnhschneider/dev/orh-hackathon/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:17:1744)
at eq (/Users/johnhschneider/dev/orh-hackathon/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:17:3076)
at div
at eY (/Users/johnhschneider/dev/orh-hackathon/node_modules/next/dist/compiled/next-server/pages.runtime.dev.js:26:763)
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js
:warning: Fast Refresh had to perform a full reload. Read more: Fast Refresh had to perform full reload | Next.js

Also with these options that databindings don’t even seem to work at all in the page builder as I map fields to the values and they don’t change. It used to be that they would change and then the error would show up when I refreshed the page.

Hello @jhs129,

We are investigating this issue internally, and we will update you as soon as we make any progress.

Thanks,

Hello @jhs129,

We wanted to let you know that we have released a fix to address the hydration mismatch errors in the latest version of the SDK (@buidler.io/react@4.0.4).

We hope this update resolves the issue for you! Please feel free to contact us if you have any further questions or concerns.

Thanks,

Manish-

That is great news. So to confirm how I get this update would I just update my package.json as follows:

“dependencies”: {
“@builder.io/dev-tools”: “^0.2.22”,
“@builder.io/react”: “^4.0.4”,
“@builder.io/react-hydration-overlay”: “^0.1.0”,
“@builder.io/sdk”: “^2.2.2”,

Actually, I can confirm with that update to my package.json the issue is now resolved. Glad y’all were able to figure it out.

1 Like