Skip to content

How to catch wasm runtime loading error? #377

Description

@mattp0123

Let's say there's no network connection while loading rive.wasm, how do I able to know there's an error loading wasm?

window.onerror = () => {
  // won't catch wasm loading error
}

window.onunhandledrejection = () => {
  // won't catch wasm loading error
}

const loadingRiveFile = (async () => {
  const file = new RiveFile({ src: '...' })
  try {
    await file.init()
  } catch {
    // won't catch wasm loading error
  }
  return file
})()

function MyComponent() {
  const riveFile = use(loadingRiveFile)
  const { RiveComponent } = useRive({
    riveFile,
    onLoadError: () => {
      // won't catch wasm loading error
    }
  })
  return (
    // ...
  )
}

function App() {
  return (
    <Suspense fallback={'loading...'}>
      <MyComponent />
    </Suspense>
  )
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions