@@ -34,14 +34,24 @@ export const Stepper = () => {
3434 prevStepsRef . current = steps ;
3535
3636 if ( steps . length > prevSteps . length ) {
37- // A step was added — activate the newly inserted step (second-to-last, just before success).
38- const newStep = steps [ steps . length - 2 ] ;
39- if ( newStep ) {
40- setActiveStepId ( newStep . id ) ;
37+ if ( ! activeStepId ) {
38+ // No active step yet (initial mount) — activate the first step.
39+ const firstStep = steps [ 0 ] ;
40+ setActiveStepId ( firstStep . id ) ;
4141 editor . executeCommand ( Commands . SendPreviewMessage , {
4242 type : "fub.activeStepChanged" ,
43- payload : { stepId : newStep . id }
43+ payload : { stepId : firstStep . id }
4444 } ) ;
45+ } else {
46+ // A step was added — activate the newly inserted step (second-to-last, just before success).
47+ const newStep = steps [ steps . length - 2 ] ;
48+ if ( newStep ) {
49+ setActiveStepId ( newStep . id ) ;
50+ editor . executeCommand ( Commands . SendPreviewMessage , {
51+ type : "fub.activeStepChanged" ,
52+ payload : { stepId : newStep . id }
53+ } ) ;
54+ }
4555 }
4656 } else if ( steps . length < prevSteps . length ) {
4757 // A step was deleted — if it was the active one, fall back to the previous step.
@@ -57,14 +67,6 @@ export const Stepper = () => {
5767 } ) ;
5868 }
5969 }
60- } else if ( steps . length && ! activeStepId ) {
61- // No active step yet (initial mount) — activate the first step.
62- const firstStep = steps [ 0 ] ;
63- setActiveStepId ( firstStep . id ) ;
64- editor . executeCommand ( Commands . SendPreviewMessage , {
65- type : "fub.activeStepChanged" ,
66- payload : { stepId : firstStep . id }
67- } ) ;
6870 }
6971 } , [ steps ] ) ;
7072
0 commit comments