Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panel: abort overlapping Fiber requests #6674

Draft
wants to merge 1 commit into
base: develop-minor
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion I would probably call it abortController to make instantly clear what this is controlling.

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
Loading