Skip to content

the 'in' guard works only if the state is defined by a complete path or a 'custom' id but it should work also with relative pathΒ #2926

@jbouecke

Description

@jbouecke

Description
If a transition is guarded via an 'in' property, the state that is referenced there cannot be addressed in the same way the 'target' is addressed. This isn't documented and also no good behaviour.

Expected Result

If the state in the transition that the machine must be 'in' is rerenced via a 'custom' id, it works, if it is referenced with a 'complete' path (including top level state 'name'), it also works, but not if it is referenced via relative path like it is usually done for 'target'.

Actual Result

There is no error, but the guard is just 'never' passed.

Reproduction

see the following machine definition:

createMachine({
  id: "example",
  initial: "TopeLevelState",
  states: {
    TopeLevelState: {
      type: "parallel",
      states: {
        EFFECTED_STATE: {
          states: {
            A: {},
            B: {},
            C: {}
          },
          on: {
            A: {
              target: "EFFECTED_STATE.A",
              in: "STATE.B"
            },
            B: {
              target: "EFFECTED_STATE.B",
              in: "#SB"
            },
            C: {
              target: "EFFECTED_STATE.C",
              in: "TopeLevelState.STATE.B"
            }
          }
        },
        STATE: {
          initial: "A",
          states: {
            A: {
              on: {
                B: "B"
              }
            },
            B: {
              id: "SB",
              on: {
                A: "A"
              }
            }
          }
        }
      }
    }
  }
});

Additional context

I stumbled accros this while trying to enhance the visualizer to not show forbidden transitions as active (see this pull request)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions