rive-app / rive-react

React runtime for Rive
https://rive-app.github.io/rive-react
MIT License
824 stars 32 forks source link

"File Instance Already Deleted" Error in Next.js HMR #141

Open fdarian opened 1 year ago

fdarian commented 1 year ago

When using useRive in Next.js, it always throw "BindingError: File instance already deleted" when performing Hot-Module Reload or any change to file in Next.js development server.

Screenshot 2022-12-14 at 12 18 44
btalb commented 1 year ago

Also seeing this issue.

Seem to be able to reliably get the app working again by saving the file 3 times each time I make a change, but very disruptive nonetheless.

Idonoghue commented 1 year ago

Getting this same error during HMR on a React 17 + Vite 4 project

LunaJet commented 1 year ago

How were you able to import the .riv file into next js

zplata commented 1 year ago

@farreldarian would adding the // @refresh reset to the useRive hook here help? We clean up Rive instances once the component unmounts to clear up all C++-created objects downstream from a WASM dependency and so any Rive-based component should hard refresh state with HMR.

As an immediate solution, you might try isolating the use of Rive in your projects to its own component with the // @refresh reset comment at top, and just add that custom passthrough component wherever you had it before

patheticGeek commented 1 year ago

@zplata Still getting the same error and i am using the @rive-app/react-canvas package

fdarian commented 1 year ago

n immediate solution, you might try isolating the use of Rive in your projects to its own component with the // @refresh reset comment at top, and just add that custom passthrough component wherever you had it before

Hey, sorry for the delay. Where should I put it? tried one at the beginning of the file, on top of useRive hook, and on top of the component, has no effect.

dustinaleksiuk commented 1 year ago

I'm seeing this issue as well in Next.js. I have the Rive animation in an isolated component with a few other things, and the // @refresh reset directive at the top.

I'm using the useRive hook from @rive-app/react-canvas

spro commented 1 year ago

Isolated component approach is working for me with @rive-app/react-canvas 3.0.35 and next 13.1.1 with // @refresh reset as the very first line of the file. The animation doesn't replay (not sure if that'd be expected) but at least the error doesn't show up.

// @refresh reset

import React from "react"
import { useRive } from "@rive-app/react-canvas"

export default function HomeAnimation() {
    const { rive, RiveComponent } = useRive({
        src: "/nuve_instances.riv",
        autoplay: true,
    })

    return <RiveComponent id="animation" className="w-[600px] h-[400px]" />
}