@@ -677,27 +677,48 @@ const ConfiguratorView: FunctionComponent<ConfiguratorViewProps> = (props) => {
677
677
if ( dnsDevice ) {
678
678
const targetName = dnsDevice . target . toUpperCase ( ) ;
679
679
680
- const device = deviceTargets ?. find ( ( item ) => {
680
+ // if targetName is an empty string, then return
681
+ if ( targetName . trim ( ) . length === 0 ) {
682
+ return ;
683
+ }
684
+
685
+ const deviceMatches = deviceTargets ?. filter ( ( item ) => {
681
686
return item . targets . find ( ( target ) => {
682
687
return target . name . toUpperCase ( ) . startsWith ( targetName ) ;
683
688
} ) ;
684
689
} ) ;
685
690
691
+ if ( ! deviceMatches || deviceMatches . length === 0 ) {
692
+ return ;
693
+ }
694
+
695
+ // if multiple device matches are found, then don't select any of them
696
+ // we do not know which one is correct and do not want to pick the wrong device.
697
+ if ( deviceMatches . length > 1 ) {
698
+ console . error (
699
+ `multiple device matches found for target ${ targetName } !`
700
+ ) ;
701
+ return ;
702
+ }
703
+
704
+ const device = deviceMatches [ 0 ] ;
705
+
686
706
const dTarget =
687
707
device ?. targets . find ( ( target ) => {
688
708
return target . flashingMethod === FlashingMethod . WIFI ;
689
709
} ) ?. name ||
690
710
device ?. targets [ 0 ] . name ||
691
711
null ;
692
712
693
- setDeviceTarget ( dTarget ) ;
713
+ if ( dTarget !== deviceTarget ) {
714
+ setDeviceTarget ( dTarget ) ;
715
+ deviceOptionsRef ?. current ?. scrollIntoView ( { behavior : 'smooth' } ) ;
716
+ }
694
717
695
718
setWifiDevice ( dnsDevice . ip ) ;
696
-
697
- deviceOptionsRef ?. current ?. scrollIntoView ( { behavior : 'smooth' } ) ;
698
719
}
699
720
} ,
700
- [ deviceTargets , networkDevices ]
721
+ [ deviceTarget , deviceTargets , networkDevices ]
701
722
) ;
702
723
703
724
useEffect ( ( ) => {
0 commit comments