Skip to content

Commit

Permalink
Fixed an issue with tags not being set correctly after sending an eve…
Browse files Browse the repository at this point in the history
…nt to a machine that didn't result in selecting any transitions
  • Loading branch information
Andarist committed May 4, 2021
1 parent c1cca81 commit 64ab115
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/soft-cats-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate': patch
---

Fixed an issue with tags not being set correctly after sending an event to a machine that didn't result in selecting any transitions.
3 changes: 2 additions & 1 deletion packages/core/src/StateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,8 @@ class StateNode<
configuration: resolvedConfiguration,
transitions: stateTransition.transitions,
children,
done: isDone
done: isDone,
tags: currentState?.tags
});

const didUpdateContext = currentContext !== updatedContext;
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ describe('tags', () => {
expect(state.tags).toEqual(new Set(['yes', 'no']));
});

it('sets tags correctly after not selecting any transition', () => {
const machine = createMachine({
initial: 'a',
states: {
a: {
tags: 'myTag'
}
}
});

const state = machine.transition(machine.initialState, {
type: 'UNMATCHED'
});
expect(state.hasTag('myTag')).toBeTruthy();
});

it('tags can be single (not array)', () => {
const machine = createMachine({
initial: 'green',
Expand Down

0 comments on commit 64ab115

Please sign in to comment.