Skip to content

ViewModel trigger.on() callbacks are registered but never invoked #413

@JeppeP

Description

@JeppeP

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

  1. Create a .riv file with a ViewModel containing a trigger property
  2. Set up a Listener in Rive that fires the trigger on click
  3. 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
    }
});

  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 callbacks array is populated correctly
  • The invocation mechanism appears to be broken

Happy to provide a minimal reproduction repo if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions