Skip to content

Commit c9eef83

Browse files
committed
fix: infinite reload issues
1 parent 157327e commit c9eef83

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/Hooks/useCoordinateInfo/useCoordinateInfo.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const useCoordinateInfo = ({
9393
const [viewResolution, setViewResolution] = useState<number | undefined>(mapView?.getResolution());
9494

9595
const abortControllers = useRef<Map<string, AbortController>>(new Map());
96+
const isFetchingRef = useRef<boolean>(false);
9697

9798
const viewProjection = useMemo(() => mapView?.getProjection(), [mapView]);
9899

@@ -433,7 +434,7 @@ export const useCoordinateInfo = ({
433434
}, [mapCoordinate]);
434435

435436
useEffect(() => {
436-
if (loading) {
437+
if (isFetchingRef.current) {
437438
return;
438439
}
439440

@@ -455,6 +456,7 @@ export const useCoordinateInfo = ({
455456

456457
const fetchFeatures = async () => {
457458
try {
459+
isFetchingRef.current = true;
458460
setLoading(true);
459461
setFeatureResults(undefined);
460462

@@ -478,7 +480,6 @@ export const useCoordinateInfo = ({
478480
}
479481

480482
let allResults: FeatureLayerResult[][] = await Promise.all(promises);
481-
allResults = await Promise.all(promises);
482483

483484
if (!drillDown) {
484485
// filter empty results, order by layer index and return the first layer found
@@ -498,21 +499,22 @@ export const useCoordinateInfo = ({
498499
setFeatureResults(clonedResults);
499500
onSuccess?.();
500501
} catch (error: any) {
501-
if (error. name !== 'AbortError') {
502+
if (error.name !== 'AbortError') {
502503
Logger.error(error);
503504
}
504505
onError?.(error);
505506
}
506507
};
507508

508509
fetchFeatures().finally(() => {
510+
isFetchingRef.current = false;
509511
setLoading(false);
510512
map.getTargetElement().style.cursor = 'auto';
511513
});
512514

513515
}, [
514516
mapCoordinate, drillDown, featureResults, getResultsFromImageLayers, getResultsFromWfsLayers, map, orderedLayerUids,
515-
onError, onSuccess, loading, wfsMapLayerUids, wmsMapLayerUids, wmtsMapLayerUids
517+
onError, onSuccess, wfsMapLayerUids, wmsMapLayerUids, wmtsMapLayerUids
516518
]);
517519

518520
/**

0 commit comments

Comments
 (0)