✅ Solved: React+Rive Webgl2 Rendering disappear when data binding

Hey guys, need help ASAP. long story short, when I apply data binding in the Rive component either through the property `autoBind: true` or through making an instance and using bindViewModelInstance(instance), either way it makes the rive component kinda disappears or barely visible or buggy…

In addition, I can’t control the view model inputs, I am sure I am entering the right values.



import { Rive } from "@rive-app/webgl2";
  useEffect(() => {
    if (!canvasRef.current || !rivePath) return;

    // Clean up previous instance
    if (riveInstanceRef.current) {
      riveInstanceRef.current.cleanup();
    }

    const rive = new Rive({
      canvas: canvasRef.current,
      src: rivePath,
      autoplay: true,
      artboard,
      stateMachines: "State Machine 1",
      useOffscreenRenderer: false, // or true if you're sharing context
      onLoad: () => {

        rive.resizeDrawingSurfaceToCanvas();
        console.log("Rive (advanced) loaded");
        
        // IF YOU COMMENT THE FOLLOWING 3 LINES, THE DATA BINDING WILL BE DISABLED
        // AND THE COMPONENT WILL RENDER NORMALLY
        const vm = rive.viewModelByName('View Model 1');
        const vmi = vm.defaultInstance();
        rive.bindViewModelInstance(vmi);

        if(vm){
          dashboardRef.current = vm;
          console.log('Dashboard View Model added: ', vm)
        }else{
          console.log('NO VM')
        }
      },
      onLoadError: (err: any) => {
        console.error("Failed to load .riv:", err);
        toast.error("Rive load error");
      },
    });
    riveInstanceRef.current = rive;

    return () => {
      rive.cleanup();
    };
  }, [rivePath, artboard]);


please let me know if you have any clarifying questions. I will attach the code file for your reference. I have been trying to debug for days, read all docs, watched videos, used LLMs, no luck so far :(

RiveInput.tsx