Skip to content

Commit

Permalink
Panel: abort overlapping Fiber requests
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Sep 14, 2024
1 parent 0033956 commit 9183188
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions panel/src/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const states = [
export default {
create(plugins = {}) {
// props
this.isLoading = false;
this.controller = null;
this.isOffline = false;

this.activation = Activation(this);
Expand Down Expand Up @@ -202,6 +202,10 @@ export default {
return response?.json ?? {};
},

get isLoading() {
return this.controller !== null && this.controller.signal.aborted !== true;
},

/**
* Opens a Panel URL and sets the state.
* This is the main difference to panel.get,
Expand All @@ -219,10 +223,21 @@ export default {
if (isUrl(url) === false) {
this.set(url);
} else {
this.isLoading = true;
const state = await this.get(url, options);
this.set(state);
this.isLoading = false;
this.controller?.abort();
this.controller = new AbortController();

try {
const state = await this.get(url, {
...options,
signal: this.controller.signal
});
this.set(state);
this.controller = null;
} catch (e) {
if (e.name !== "AbortError") {
throw e;
}
}
}

return this.state();
Expand Down

0 comments on commit 9183188

Please sign in to comment.