Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: clicking a remote location and then immediately clicking another location now switches cleanly to the second one. The slow S3/WebDAV response from the first click is dropped at three layers: AbortController on the network call, abort gate in loadDirectoryContent, and the cancelled flag in the outer effect.

Ilian Sapundshievf229c7507f40
diff --git a/src/renderer/components/LocationManager.tsx b/src/renderer/components/LocationManager.tsx
index 628845a4c..ee07687dd 100644
--- a/src/renderer/components/LocationManager.tsx
+++ b/src/renderer/components/LocationManager.tsx
@@ -40,7 +40,6 @@ interface Props {
function LocationManager(props: Props) {
const { t } = useTranslation();
const {
- findLocation,
moveLocation,
setSelectedLocation,
locationDirectoryContextMenuAnchorEl,
@@ -98,7 +97,6 @@ function LocationManager(props: Props) {
};
const { reduceHeightBy, show } = props;
- const currentLocation = findLocation();
function getWorkSpace(l) {
if (l.workSpaceId) {
@@ -121,33 +119,6 @@ function LocationManager(props: Props) {
position: 'relative',
}}
>
- {currentLocation &&
- (currentLocation.haveObjectStoreSupport() ||
- currentLocation.haveWebDavSupport()) && (
- <>
- <style>
- {`
- @keyframes hide {
- to {
- width: 0;
- }
- }
- }
- `}
- </style>
- <div
- style={{
- position: 'absolute',
- zIndex: 1000,
- height: 'calc(100% - 150px)',
- left: 0,
- right: 0,
- backdropFilter: 'grayscale(1)',
- animation: 'hide 1ms linear 5s 1 forwards',
- }}
- />
- </>
- )}
<LocationManagerMenu
importLocations={() => {
fileInputRef.current.click();
diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsx
index 7882b03db..dd83a8aca 100644
--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx
+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx
@@ -324,33 +324,36 @@ export const DirectoryContentContextProvider = ({
}, []);
useEffect(() => {
- if (currentLocation) {
- // check for relative path for Location
- getLocationPath(currentLocation).then((locationPath) => {
- currentLocationPath.current = locationPath;
- if (!skipInitialDirList) {
- /*if (isLoading.current) {
- //cancel loading KanBan S3 folders on location-folder change
- abort();
- }
- isLoading.current = true;*/
- openDirectory(locationPath)
- .then((success) => {
- manualPerspective.current = 'unspecified';
- //isLoading.current = false;
- return success;
- })
- .catch((ex) => {
- //isLoading.current = false;
- console.log('Error openDirectory:', ex);
- });
- }
- });
- } else {
+ if (!currentLocation) {
currentLocationPath.current = '';
clearDirectoryContent();
exitSearchMode();
+ return;
}
+ // Latest-wins guard: if the user switches locations before this load
+ // settles, drop the stale resolution so a slow S3/WebDAV response can't
+ // overwrite the newly-active location's state. The AbortController in
+ // useCancelablePerLocation already aborts the inner network calls; this
+ // flag covers the outer chain (getLocationPath → openDirectory).
+ let cancelled = false;
+ getLocationPath(currentLocation).then((locationPath) => {
+ if (cancelled) return;
+ currentLocationPath.current = locationPath;
+ if (skipInitialDirList) return;
+ openDirectory(locationPath)
+ .then((success) => {
+ if (cancelled) return success;
+ manualPerspective.current = 'unspecified';
+ return success;
+ })
+ .catch((ex) => {
+ if (cancelled) return;
+ console.log('Error openDirectory:', ex);
+ });
+ });
+ return () => {
+ cancelled = true;
+ };
}, [currentLocation]);
useEffect(() => {
@@ -956,6 +959,9 @@ export const DirectoryContentContextProvider = ({
currentLocation,
showHiddenEntries,
).then((entries) => {
+ // Don't commit results from a load that was aborted because
+ // the user switched locations — would clear the newer location.
+ if (signal?.aborted) return entries;
setCurrentDirectoryEntries(entries);
return entries;
});
@@ -968,6 +974,7 @@ export const DirectoryContentContextProvider = ({
currentLocation,
showHiddenEntries,
).then((entries) => {
+ if (signal?.aborted) return entries;
setCurrentDirectoryEntries(entries);
return entries;
});