rive-app / rive-react

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

Fix: await file init in useRiveFile to catch async errors #270

Open petersli opened 1 week ago

petersli commented 1 week ago

@damzobridge @bodymovin

When testing out https://github.com/rive-app/rive-react/pull/269, I realized that the errors thrown by file.init() were not actually being caught by the try/catch due to init being async.

In the rive-wasm repo, in order to catch the errors thrown within the async init of the file, they use await (https://github.com/rive-app/rive-wasm/blob/6d5cd8909a635184f156be03d1f32d5ceb4025fc/js/src/rive.ts#L1739).

Testing locally, this fixes my issue!

Before: The app still crashes if I pass a bad src to useRiveFile.

After: If there's a bad src, the app does not crash anymore. If the src is valid, the Rive file loads and the animation plays as expected.