fix: separate trigger hook lifecycle to prevent missed events on Android#262
Open
mfazekas wants to merge 5 commits into
Open
fix: separate trigger hook lifecycle to prevent missed events on Android#262mfazekas wants to merge 5 commits into
mfazekas wants to merge 5 commits into
Conversation
…oid (#230) Remove onPropertyEventOverride from useRiveProperty — triggers now manage their own property lifecycle in useRiveTrigger with a ref-based callback, avoiding the bailout bug where useDisposableMemo disposes during render but the subscription effect is skipped.
Tests that trigger events are received after rapid re-renders with unstable callback references — the scenario that caused silent trigger loss before the fix.
Use toBeGreaterThanOrEqual(3) instead of toBeGreaterThan(5) since the exact re-render count varies by platform and React Strict Mode config.
The Rive render loop must be running for pollChanges() to dispatch trigger events to listeners. Without a RiveView, trigger() fires at the native level but the listener callback never receives it.
pollChanges() runs on frame ticks so rapid consecutive trigger() calls can coalesce into a single listener notification.
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.
Fixes #230
Unstable
onTriggercallback references causeuseRiveTriggerto silently stop receiving events on Android after re-renders.useRiveTriggernow manages its own property lifecycle (likeuseRiveList) instead of going throughuseRiveProperty. The callback is stored in a ref so its identity doesn't affect native property disposal.useRivePropertyis simplified — theonPropertyEventOverrideescape hatch is removed and theoptionsparameter becomes a plaingetPropertyfunction.Root cause and reproducer
Root cause
useDisposableMemodisposes the old native property and creates a new one during the render phase (via ref mutation). When the callback identity changes (e.g.onTriggerwithout React Compiler memoization),optionschanges, which triggers this dispose/create cycle.The problem: if a no-op state update (like
setError(null)when error is already null) triggers a re-render that produces identical JSX output, React bails out — it runs the component function but skips the commit and effects. SinceuseEffectis skipped, the listener is never re-subscribed to the new property.The property is orphaned — disposed old one is dead, new one has no listener. All subsequent trigger events are silently lost.
Reproducer