rive-app / rive-react

React runtime for Rive

Home Page:https://rive-app.github.io/rive-react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rive.wasm blocking website load

carolinmaisenbacher opened this issue · comments

I am currently developing a Gatsby website that uses a few Rive animations with the help of rive-react.

In development it works great, however whenever building my website the loading speeds for the first paint get very slow.

I noticed that a 3rd party request to get rive.wasm is what is blocking my website.
I am attaching some screenshots below.

Do you have any advice how I can make the request faster? Is it possible to host the rive.wasm file e.g. on my own server?

Any help is appreciated!

Here is the request summary, which shows it took 93ms to get the rive file:
Screenshot 2022-06-15 at 11 40 09

These are the request details:
Screenshot 2022-06-15 at 11 41 00

@carolinmaisenbacher Oh good question! Right now, the WASM gets requested implicitly as you discovered. In the downstream JS/WASM runtime, we have a lower-level API package that lets you build the render loop yourself, and set the WASM file yourself (which seems of interest here) which is a little more involved. We don't bubble that up as a React affordance at the moment, but we can probably find some solution at the lower level to supply the WASM and allow you to do the same in React. You can download the WASM file itself via the URL in that screenshot and save that in your server, however, each new version of @rive-app/canvas will have a new WASM file so you'd just need to be diligent about making sure you use the version associated with the one this repo uses as a dependency.

im having issues rending on an ec2 for some reason.. it works localy but when i push to developement nothing shows up.. spent the day trying to figure why... since my request looks the same as the screen shot from Carolin. Im wondering if im having the same issue with rending here? cant figure out how to debug at the moment and its sucks cuz i really want to use this anmination and more in my react project

Actually, you might be able to host the WASM file on your own server and be able to serve this up!

import Rive, { RuntimeLoader } from "@rive-app/react-canvas";

RuntimeLoader.setWasmUrl("http://your-own-server.com/rive.wasm");

function App() {
  return (
    <div>
      <Rive src="https://cdn.rive.app/animations/vehicles.riv" />
    </div>
  );
}

We can work on making the URL you'd like to set as a param you pass into <Rive> or useRive() but you could do this in the meantime, and then it shouldn't try to request the wasm from unpkg by default.

To download the correlated WASM file for your server, check out the dependency version of @rive-app/canvas in the tagged version of @rive-app/react-canvas you're consuming. For example, 1.0.71: https://github.com/rive-app/rive-react/blob/v3.0.15/package.json#L32

The correlated WASM file should be the following URL with the version identified above:

https://unpkg.com/@rive-app/canvas@1.0.71/rive.wasm

@carolinmaisenbacher @3lonious

hey im unable to install react-canvas with my current config...

any other ideas?

i may have got it working one sec

ok its working... like this
Screen Shot 2022-07-05 at 10 52 15 AM

needing to get this one tho from cdn? how do i find them to use the way i have setup?

https://rive.app/community/65-358-iron-giant-demo/

figured it out with inspect and network calls but would be great to have that url copable from community listings animation page

thanks for the help tho on this!

Thank you for your detailed reply @zplata!
Your solution of setting the wasm url with setWasmUrl worked flawlessly for me.