Skip to content

How to catch wasm runtime loading error? #377

@mattp0123

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>
  )
}

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