Next.js Discord

Discord Forum

Getting a Cannot read properties of undefined (reading 'getPropertyValue') in a client component.

Unanswered
zeusgmj posted this in #help-forum
Open in Discord
I have a server component called Card.jsx and I import a client component called MeshGradient.jsx into Card.jsx.

  return (
    // other elements
    <MeshGradient colors={additonalColors} gradientId={'gradient-canvas-now-playing'} />
  );


I'm using the code from https://gist.github.com/jordienr/64bcf75f8b08641f205bd6a1a0d4ce1d which is pasted into a file called Gradient.js, and then import it into the MeshGradient component.

MeshGradient.jsx
'use client';
import { Gradient } from '../../../../../lib/utils/Gradient';
import { useEffect, useRef } from 'react';

export default function MeshGradient({ gradientId, colors }) {
  const gradient = new Gradient();
  const ref = useRef(null);

  useEffect(() => {
    if (ref.current) {
      gradient.init(`#${gradientId}`);
    }
  }, [ref]);

  return (
    <canvas
      ref={ref}
      style={{
        '--gradient-color-1': colors[0],
        '--gradient-color-2': colors[1],
        '--gradient-color-3': colors[2],
        '--gradient-color-4': colors[3],
      }}
      className='absolute left-0 top-0 h-full w-full rounded-3xl'
      id={gradientId}
      data-transition-in
    />
  );
}


I'm not sure what I'm doing wrong here, but it throws an error at line 494.

6 Replies

I've made a small demo of the code in codesandbox
https://codesandbox.io/p/devbox/zealous-dan-8pzw8t
Adding a timeout inside useEffect doesn't seem to help too 🥲🥲
No one has an idea about this?🥲
Toyger
it's client only class, you can try to import it with disabled ssr, but I doubt it will help, because nextjs more suitable for functions not classes. More likely you need to have some condition like if window is undefined for ssr then disable it, but because it is js class it's harder to manipulate it like that, so probably there is no easy way to fix it.
Ah damn :/
I guess I need to look at an alternate for this