fix: prevent crash when trigger is called after dispose#268
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a crash caused by calling trigger() from stale closures after a RiveView unmounts/cleans up its native trigger property, by tracking whether the underlying native property is still “live” and safely no-op’ing when it isn’t.
Changes:
- Add optional
liveReftracking touseDisposableMemo(set on create, cleared on dispose). - Thread
liveRefthroughuseRivePropertyoptions so hooks can observe property liveness. - Update
useRiveTriggerto calltrigger()vialiveRefand warn/no-op instead of crashing after disposal.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/hooks/useRiveTrigger.ts | Switches trigger execution to a liveness-tracked ref and adds a warning/no-op path. |
| src/hooks/useRiveProperty.ts | Extends property options to accept a liveRef and forwards it into disposable memoization. |
| src/hooks/useDisposableMemo.ts | Adds liveRef support and clears/sets it alongside disposal/creation lifecycle. |
Comments suppressed due to low confidence (1)
src/hooks/useDisposableMemo.ts:70
liveRefis only synchronized inside the deps-change/initialization branch. If a caller starts passing aliveRefafter the initial render (or swaps to a different ref) whiledepsremain equal, the new ref will never be populated with the current value. Consider handlingliveRefchanges by immediately syncingliveRef.currentto the current memoized value (and clearing any previous liveRef) even when deps are unchanged.
if (
ref.current.deps === UNINITIALIZED ||
!depsEqual(ref.current.deps, deps)
) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6f29d17 to
6ed8d9b
Compare
useDisposableMemo now accepts an optional liveRef that is set on create and cleared on dispose (including unmount). useRiveTrigger uses this to safely no-op when called from stale closures (e.g. Reanimated callbacks that fire after navigation).
Address Copilot review: only warn when trigger() is called after the property was disposed, not when the viewModelInstance isn't available yet. Add liveRef tests to useDisposableMemo and new useRiveTrigger test suite.
6ed8d9b to
785335b
Compare
HayesGordon
approved these changes
May 22, 2026
Contributor
HayesGordon
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the quick fix
mfazekas
pushed a commit
that referenced
this pull request
May 22, 2026
🤖 I have created a release *beep* *boop* --- ## [0.4.9](v0.4.8...v0.4.9) (2026-05-22) ### Bug Fixes * prevent crash when trigger is called after dispose ([#268](#268)) ([13d9dc1](13d9dc1)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Calling
trigger()from a stale closure (e.g. a Reanimated callback that fires after navigation/unmount) would crash because the native property was already disposed.useDisposableMemonow accepts an optionalliveRefparameter — set on create, cleared on dispose.useRiveTriggeruses this to safely no-op with aconsole.warninstead of crashing.Reproducer: mount RiveView with trigger → unmount → call trigger from async callback.