fix: abort ongoing requests when changing pages (#3927)

This commit is contained in:
manx98
2025-06-29 15:38:03 +08:00
committed by GitHub
parent 2d1a82b73f
commit 93c4b2e03c
6 changed files with 75 additions and 24 deletions

View File

@@ -31,6 +31,7 @@ import { useFileStore } from "@/stores/file";
import url from "@/utils/url";
import { files } from "@/api";
import { StatusError } from "@/api/utils.js";
export default {
name: "file-list",
@@ -43,6 +44,7 @@ export default {
},
selected: null,
current: window.location.pathname,
nextAbortController: new AbortController(),
};
},
inject: ["$showError"],
@@ -56,7 +58,13 @@ export default {
mounted() {
this.fillOptions(this.req);
},
unmounted() {
this.abortOngoingNext();
},
methods: {
abortOngoingNext() {
this.nextAbortController.abort();
},
fillOptions(req) {
// Sets the current path and resets
// the current items.
@@ -94,8 +102,17 @@ export default {
// just clicked in and fill the options with its
// content.
const uri = event.currentTarget.dataset.url;
files.fetch(uri).then(this.fillOptions).catch(this.$showError);
this.abortOngoingNext();
this.nextAbortController = new AbortController();
files
.fetch(uri, this.nextAbortController.signal)
.then(this.fillOptions)
.catch((e) => {
if (e instanceof StatusError && e.is_canceled) {
return;
}
this.$showError(e);
});
},
touchstart(event) {
const url = event.currentTarget.dataset.url;