Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: invoked callback not working with predictableActionArguments #3548

Closed
customcommander opened this issue Aug 25, 2022 · 0 comments · Fixed by #3549
Closed

Bug: invoked callback not working with predictableActionArguments #3548

customcommander opened this issue Aug 25, 2022 · 0 comments · Fixed by #3549
Assignees
Labels

Comments

@customcommander
Copy link

Description

The "ping pong" machine example doesn't work when predictableActionArguments is set to true:
https://xstate.js.org/docs/guides/communication.html#invoking-callbacks.

I copy/pasted (and instrumented the code):

const { createMachine, interpret, send } = require('xstate');

const pingPongMachine = createMachine({
  predictableActionArguments: true,
  id: 'pinger',
  initial: 'active',
  states: {
    active: {
      invoke: {
        id: 'ponger',
        src: (context, event) => (callback, onReceive) => {
          console.log('ponger init')
          // Whenever parent sends 'PING',
          // send parent 'PONG' event
          onReceive((e) => {
            if (e.type === 'PING') {
              console.log('ponger done')
              callback('PONG');
            }
          });
        }
      },
      entry: send({ type: 'PING' }, { to: 'ponger' }),
      on: {
        PONG: { target: 'done' }
      }
    },
    done: {
      type: 'final'
    }
  }
});

interpret(pingPongMachine)
  .onDone(() => console.log('done!'))
  .start();

Expected result

Expected output:

ponger init
ponger done
done!

Actual result

Actual output:

ponger init

Reproduction

https://codesandbox.io/s/lucid-gauss-hnuq18?file=/src/index.js

Additional context

If you set predictableActionArguments to false then we get the expected output.

This was observed in v4.33.3.

In v4.33.2 we get the expected output regardless of the value of predictableActionArguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants