@@ -657,33 +657,31 @@ Breaking change
657
657
658
658
:::
659
659
660
- All transitions are implicitly internal. This change is relevant for transitions defined on compound state nodes with ` entry ` or ` exit ` actions, invoked actors or delayed transitions (` after ` ). If you relied on implicit re-entering of a compound state node, use ` reenter: true ` :
660
+ All transitions are implicitly internal. This change is relevant for transitions defined on compound state nodes with ` entry ` or ` exit ` actions, invoked actors, or delayed transitions (` after ` ). If you relied on implicit re-entering of a compound state node, use ` reenter: true ` :
661
661
662
662
<Tabs >
663
663
<TabItem value = " v5" label = " XState v5 beta" >
664
664
665
665
``` ts
666
666
// ✅
667
- const machine = createMachine (
668
- {
669
- // ...
670
- states: {
671
- compoundState: {
672
- entry: ' someAction' ,
673
- on: {
674
- someEvent: {
675
- target: ' compoundState.childState' ,
676
- reenter: true , // make it external explicitly!
677
- },
678
- },
679
- initial: ' childState' ,
680
- states: {
681
- childState: {},
667
+ const machine = createMachine ({
668
+ // ...
669
+ states: {
670
+ compoundState: {
671
+ entry: ' someAction' ,
672
+ on: {
673
+ someEvent: {
674
+ target: ' compoundState.childState' ,
675
+ reenter: true , // make it external explicitly!
682
676
},
683
677
},
678
+ initial: ' childState' ,
679
+ states: {
680
+ childState: {},
681
+ },
684
682
},
685
683
},
686
- )
684
+ } )
687
685
```
688
686
689
687
</TabItem >
@@ -692,26 +690,24 @@ const machine = createMachine(
692
690
693
691
``` ts
694
692
// ❌ DEPRECATED
695
- const machine = createMachine (
696
- {
697
- // ...
698
- states: {
699
- compoundState: {
700
- entry: ' someAction' ,
701
- on: {
702
- someEvent: {
703
- // implicitly external
704
- target: ' compoundState.childState' , // non-relative target
705
- },
706
- },
707
- initial: ' childState' ,
708
- states: {
709
- childState: {},
693
+ const machine = createMachine ({
694
+ // ...
695
+ states: {
696
+ compoundState: {
697
+ entry: ' someAction' ,
698
+ on: {
699
+ someEvent: {
700
+ // implicitly external
701
+ target: ' compoundState.childState' , // non-relative target
710
702
},
711
703
},
704
+ initial: ' childState' ,
705
+ states: {
706
+ childState: {},
707
+ },
712
708
},
713
709
},
714
- )
710
+ } )
715
711
```
716
712
717
713
</TabItem >
@@ -722,25 +718,88 @@ const machine = createMachine(
722
718
723
719
``` ts
724
720
// ✅
725
- const machine = createMachine (
726
- {
727
- // ...
728
- states: {
729
- compoundState: {
730
- after: {
731
- 1000 : {
732
- target: ' compoundState.childState' ,
733
- reenter: true , // make it external explicitly!
734
- }
721
+ const machine = createMachine ({
722
+ // ...
723
+ states: {
724
+ compoundState: {
725
+ after: {
726
+ 1000 : {
727
+ target: ' compoundState.childState' ,
728
+ reenter: true , // make it external explicitly!
729
+ }
730
+ },
731
+ initial: ' childState' ,
732
+ states: {
733
+ childState: {},
734
+ },
735
+ },
736
+ },
737
+ })
738
+ ```
739
+
740
+ </TabItem >
741
+
742
+ <TabItem value = " v4" label = " XState v4" >
743
+
744
+ ``` ts
745
+ // ❌ DEPRECATED
746
+ const machine = createMachine ({
747
+ // ...
748
+ states: {
749
+ compoundState: {
750
+ after: {
751
+ 1000 : {
752
+ // implicitly external
753
+ target: ' compoundState.childState' , // non-relative target
754
+ }
755
+ },
756
+ initial: ' childState' ,
757
+ states: {
758
+ childState: {},
759
+ },
760
+ },
761
+ },
762
+ })
763
+ ```
764
+
765
+ </TabItem >
766
+ </Tabs >
767
+
768
+ ### Child state nodes are always re-entered
769
+
770
+ :::breakingchange
771
+
772
+ Breaking change
773
+
774
+ :::
775
+
776
+ Child state nodes are always re-entered when they are targeted by transitions (both external and ** internal** ) defined on compound state nodes. This change is relevant only if a child state node has ` entry ` or ` exit ` actions, invoked actors, or delayed transitions (` after ` ). Add a ` stateIn ` guard to prevent undesirable re-entry of the child state:
777
+
778
+ <Tabs >
779
+ <TabItem value = " v5" label = " XState v5 beta" >
780
+
781
+ ``` ts
782
+ // ✅
783
+
784
+ const machine = createMachine ({
785
+ // ...
786
+ states: {
787
+ compoundState: {
788
+ on: {
789
+ someEvent: {
790
+ guard: not (stateIn (' compoundState.childState' )),
791
+ target: ' .childState' ,
735
792
},
736
- initial: ' childState' ,
737
- states: {
738
- childState: {},
793
+ },
794
+ initial: ' childState' ,
795
+ states: {
796
+ childState: {
797
+ entry: ' someAction' ,
739
798
},
740
799
},
741
800
},
742
801
},
743
- )
802
+ } )
744
803
```
745
804
746
805
</TabItem >
@@ -749,30 +808,30 @@ const machine = createMachine(
749
808
750
809
``` ts
751
810
// ❌ DEPRECATED
752
- const machine = createMachine (
753
- {
754
- // ...
755
- states: {
756
- compoundState: {
757
- after: {
758
- 1000 : {
759
- // implicitly external
760
- target: ' compoundState.childState' , // non-relative target
761
- }
811
+
812
+ const machine = createMachine ({
813
+ // ...
814
+ states: {
815
+ compoundState: {
816
+ on: {
817
+ someEvent: {
818
+ target: ' .childState' , // implicitly internal, childState not re-entered
762
819
},
763
- initial: ' childState' ,
764
- states: {
765
- childState: {},
820
+ },
821
+ initial: ' childState' ,
822
+ states: {
823
+ childState: {
824
+ entry: ' someAction' ,
766
825
},
767
826
},
768
827
},
769
828
},
770
- )
829
+ } )
771
830
```
772
831
773
832
</TabItem >
774
- </Tabs >
775
833
834
+ </Tabs >
776
835
777
836
### Use ` stateIn() ` to validate state transitions, not ` in `
778
837
0 commit comments