-
Notifications
You must be signed in to change notification settings - Fork 75
Open
Description
Summary
When using the ViewModel Instance API to observe triggers via trigger.on(callback), callbacks are correctly registered but never invoked when the trigger fires.
Environment
- Runtime: @rive-app/canvas v2.32.2
- Browser: Chrome 131 (also tested in Safari)
- OS: macOS
Steps to Reproduce
- Create a .riv file with a ViewModel containing a trigger property
- Set up a Listener in Rive that fires the trigger on click
- In JavaScript, observe the trigger:
javascript
const rive = new Rive({
src: 'file.riv',
canvas: document.querySelector('canvas'),
stateMachines: ['StateMachine'],
autoBind: true,
onLoad: () => {
const vmi = rive.viewModelInstance;
const trigger = vmi.trigger('myTrigger');
console.log('callbacks before:', trigger.callbacks?.length); // 0
trigger.on(() => {
console.log('Trigger fired!'); // Never called
});
console.log('callbacks after:', trigger.callbacks?.length); // 1
}
});
- Click the element that should fire the trigger
Expected Behavior
The callback passed to trigger.on() should be invoked when:
- The trigger fires from a Rive Listener interaction
trigger.trigger()is called from JavaScript
Actual Behavior
- Callback is registered (callback count increases from 0 to 1)
- Callback is never invoked
- Manually calling
trigger.callbacks.forEach(cb => cb())does work
Workaround
Currently using onStateChange to detect state transitions as a fallback for navigation triggers.
Additional Context
- The
.on()method exists and accepts callbacks - Internal
callbacksarray is populated correctly - The invocation mechanism appears to be broken
Happy to provide a minimal reproduction repo if needed.
Metadata
Metadata
Assignees
Labels
No labels