Skip to content

Bug: stateIn guard does not work with parallel state IDs (v5) #4383

@rlaffers

Description

@rlaffers

Description

The stateIn guard helper does not parse strings starting with #id, where "id" is an ID assigned to a parallel state.

// a parallel state region with an ID
B: {
  id: 'b',
  states: {
    B1: {},
  },
},

// elsewhere
guard: stateIn('#b.B1'), // ❌ the guard returns false even if the machine is in #b.B1

Expected result

The string passed to stateIn is correctly parsed. If a string starts with #id, the id is recognized if it is assigned to a state node within the current machine. The guard should pass.

Actual result

The guard did not pass.

Reproduction

https://codesandbox.io/s/pensive-rumple-w9wsdj?file=/src/index.js

Additional context

The stateIn guard works correctly only in the following scenarios:

guard: stateIn('B.B1'), // ✅
guard: stateIn('#root.B.B1'), // ✅ the string starts with an ID defined at the top level of the machine config
guard: stateIn({ B: 'B1' }) // ✅

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions