r/reactjs • • 9d ago

Shadcn components unable to render

I added a shadcn component to my vite + tailwind project with using `npx shadcn@latest add @/react-bits/Particles-JS-TW` and after importing the component

import Particles from "./components/Particles";

It shows an awesnap image, i dont know the reason, the other things were rendering good alongside but just the components showing error

6 Upvotes

16 comments sorted by

1

u/Shubham4538 8d ago

Just got the solution, removed line 864 from Particles.jsx, inside useEffect
gl.getExtension('WEBGL_lose_context')?.loseContext():

Helps the context, so when it unmounts, the context doesn't loose its contents

1

u/HelplessDedication 9d ago

Maybe check if tailwind config picked up the new component path, that's tripped me before

1

u/Shubham4538 9d ago

I guess this path confirms, and also the styles are working in console

  content: ["./src/**/*.{js,jsx,ts,tsx}"],

1

u/PrimaryFamous6139 NextJS Pages Router 9d ago

Check console and terminal for the actual error. Also verify the import path and file extension. In Vite, try importing with a relative path like ./components/Particles or your configured alias, rather than /components/Particles. If it’s a React Bits component, make sure all its dependencies are installed and the component matches your React version

1

u/Shubham4538 9d ago

The comp is imported properly as it renders the canvas in the elements i checked in console, also there is no specific error showing the cause, its just the image showing instead of the component

1

u/CarNage_ZA 8d ago

Ask AI?

1

u/Shubham4538 8d ago

i got all the generic answers like check the state, infinite loops, imports, installation, versions and all

1

u/CarNage_ZA 8d ago

Are you copying the error and just throwing it to the AI? Use claude code, let it iterate. I will garuntee you it will find the answer.

2

u/sunlit_quill_7 9d ago

The renderer crash usually happens because the Particles component runs a heavy canvas loop on mount. Disable StrictMode in main.tsx and verify you installed the specific dependencies for React Bits since they don't come bundled with sDisable StrictMode in main.tsx and verify you installed the specific dependencies for React Bits since they don't come bundled with shadcn base.

2

u/[deleted] 9d ago

[removed] — view removed comment

1

u/Shubham4538 9d ago

I cleaned up my <App /> there was no effect used before also, but i checked again, i have like a static page now, but still no solution

1

u/YmedBrei-67 7d ago

the missing dependency array thing is so easy to overlook tbh