@@ -437,6 +437,7 @@ import { ref, reactive, toRaw } from 'vue'
437
437
import { api } from ' @/api'
438
438
import { mixinDevice } from ' @/utils/mixin.js'
439
439
import { genericCompare } from ' @/utils/sort.js'
440
+ import { sourceToken } from ' @/utils/request'
440
441
import store from ' @/store'
441
442
import eventBus from ' @/config/eventBus'
442
443
@@ -616,6 +617,9 @@ export default {
616
617
next ()
617
618
},
618
619
beforeRouteLeave (to , from , next ) {
620
+ console .log (' DEBUG - Due to route change, ignoring results for any on-going API request' , this .apiName )
621
+ sourceToken .cancel ()
622
+ sourceToken .init ()
619
623
this .currentPath = this .$route .fullPath
620
624
next ()
621
625
},
@@ -885,19 +889,30 @@ export default {
885
889
break
886
890
}
887
891
}
888
- this . itemCount = 0
892
+ var apiItemCount = 0
889
893
for (const key in json[responseName]) {
890
894
if (key === ' count' ) {
891
- this . itemCount = json[responseName].count
895
+ apiItemCount = json[responseName].count
892
896
continue
893
897
}
894
898
objectName = key
895
899
break
896
900
}
901
+
902
+ if (' id' in this .$route .params && this .$route .params .id !== params .id ) {
903
+ console .log (' DEBUG - Discarding API response as its `id` does not match the uuid on the browser path' )
904
+ return
905
+ }
906
+ if (this .dataView && apiItemCount > 1 ) {
907
+ console .log (' DEBUG - Discarding API response as got more than one item in data view' , this .$route .params , this .items )
908
+ return
909
+ }
910
+
897
911
this .items = json[responseName][objectName]
898
912
if (! this .items || this .items .length === 0 ) {
899
913
this .items = []
900
914
}
915
+ this .itemCount = apiItemCount
901
916
902
917
if ([' listTemplates' , ' listIsos' ].includes (this .apiName ) && this .items .length > 1 ) {
903
918
this .items = [... new Map (this .items .map (x => [x .id , x])).values ()]
@@ -946,6 +961,10 @@ export default {
946
961
}
947
962
}
948
963
}).catch (error => {
964
+ if (! error || ! error .message ) {
965
+ console .log (' API request likely got cancelled due to route change:' , this .apiName )
966
+ return
967
+ }
949
968
if ([401 ].includes (error .response .status )) {
950
969
return
951
970
}
0 commit comments