statelyai / xstate-tools

Public monorepo for XState tooling
183 stars 40 forks source link

Visualizer does not render delay arrays #64

Closed mdpratt closed 2 years ago

mdpratt commented 2 years ago

Machines that define an array for the after attribute do not correctly rendering the node.

Code: https://stately.ai/viz/29788792-45db-4927-9d66-590e9ecbbf65

const example = createMachine({
  states: {
    idle: {
      after: [
        {
          delay: 1000,
          target: 'pending',
        },
      ],
    },
    pending: {},
  },
});

Expected: image

Actual: image

mdpratt commented 2 years ago

It looks like after arrays are generally not being handled correctly. Defining a guard (eg. after: [{ delay: settings.paginationDelay ?? 100, target: 'pending', cond: 'isPaginationAutomatic' }] will cause the the TypeGen to fail with the following error messages:

Typescript will fail:

Object literal may only specify known properties, and 'isPaginationAutomatic' does not exist in type 'MachineOptionsGuards<{ ...snip...}>

XState VSCode extension will warn:

isPaginationAutomatic is never used in the machine definition

If the same guard is used in an on handler for a state, then the warnings go away.

mattpocock commented 2 years ago

Duplicate of #44

mdpratt commented 2 years ago

Is the visualization and typegen related to the same flaw? If not, I'd recommend reopening this issue.

mattpocock commented 2 years ago

Yes, it is - it's a parsing issue