`useRive` React component lifecycle related init issue
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- react, typescript
- Domain
- frontend
Research direction
Start with the linked StackBlitz reproduction and inspect the useRive hook in @rive-app/react-canvas@4.3.3. Trace initialization across the conditional mount and unmount cycle, then verify that the RiveComponent initializes and autoplays every time it is remounted.
Written by the indexing model from the issue text.
Description
Hello there! 👋
We are using useRive from this library for animations within our DesignSystem, and have noticed a pretty critical React component lifecycle related bug with the useRive hook. 😭
I've produced a simple reproduction of this bug in the latest published version of useRive from @rive-app/react-canvas@4.3.3
https://stackblitz.com/edit/stackblitz-starters-tc2yg6?file=app%2Fpage.tsx
Essentially, when first revealed (mounted), the Rive animation inits and autoplays as expected. However, once it's unmounted and then re-mounted (in this case using a simple conditional render bool) - the rive animation fails to init and autoplay.
Here is a simple code snippet which demonstrates the issue:
...
const [show, setShow] = useState(false);
const { RiveComponent } = useRive({
src: 'https://cdn.rive.app/animations/vehicles.riv',
autoplay: true,
layout: new Layout({
fit: Fit.Cover,
alignment: Alignment.Center,
}),
});
return (
<div>
<button onClick={() => setShow((old) => !old)}>toggle</button>
{show && <RiveComponent style={{ width: '500px', height: '500px' }} />} {/*<-- this only loads up and plays the very first time it's mounted. :( */}
</div>
);
...
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 58
- Avg merge
- 3h 23m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from rive-app/rive-react
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
rive-app/rive-react#440 · 5 comments · 4 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
rive-app/rive-react#410 · 1 comment ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 42/100
rive-app/rive-react#409 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
rive-app/rive-react#400 ·
-
triage
Difficulty 3/5 1-2 days Newbie friendliness 45/100
rive-app/rive-react#392 ·
All issues in rive-app/rive-react
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
danielmiessler/LifeOS#2218 ·