Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.riv url is re-fetched many times #205

Closed
hckhanh opened this issue Sep 9, 2023 · 2 comments
Closed

.riv url is re-fetched many times #205

hckhanh opened this issue Sep 9, 2023 · 2 comments

Comments

@hckhanh
Copy link

hckhanh commented Sep 9, 2023

When ever I reuse the component that load the .riv file it's still re-fetched the riv file again no matter how many time it is fetched before. Is there any caching mechanism to deal with it? I am using vite and import it as an url

import animationSaladin from '@/assets/animations/file.riv?url'
import { useColorScheme } from '@/states/theme'
import Rive from '@rive-app/react-canvas'
import { memo } from 'react'

const styles = { width: 150, height: 150 }

function LoadingOverlayLoader() {
  const colorScheme = useColorScheme()
  return (
    <Rive
      artboard='Logo'
      src={animationSaladin}
      stateMachines={colorScheme}
      style={styles}
    />
  )
}

export default memo(LoadingOverlayLoader)
@hckhanh hckhanh changed the title Riv url is refetched many times .riv url is refetched many times Sep 9, 2023
@hckhanh hckhanh changed the title .riv url is refetched many times .riv url is re-fetched many times Sep 9, 2023
@EliotSlevin
Copy link

@hckhanh I think this issue was a similar case, and came to a good solution? #153

@damzobridge
Copy link
Contributor

We've released a new useRiveFile hook that should address this. See #153 .

Now you can pass in an existing RiveFile instance for an animation to the LoadingOverlayLoader instead of instantiating within the component. This lets you cache the RiveFile instance outside the component and use it across multiple components while fetching it only once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants