diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/OriginInfo/ConnectionFormOriginInfoFormPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/OriginInfo/ConnectionFormOriginInfoFormPart.ts index 09926149fd2..c84d0a6f98c 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/OriginInfo/ConnectionFormOriginInfoFormPart.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/OriginInfo/ConnectionFormOriginInfoFormPart.ts @@ -33,7 +33,32 @@ export class ConnectionFormOriginInfoFormPart extends FormPart) { + private authStateTask?: Promise; + private authStateTaskKey?: string; + + // formAuthState can be called multiple times by the form flow, + // which triggers multiple calls to resources and triggers "execution queue limit reached" error + // probably the core issue is in the resource and we need to wait to release the loader there, + // but we need more cases to say so + private formAuthState(data: IConnectionFormState, contexts: IExecutionContextProvider): Promise { + const connectionKey = this.optionsPart.connectionKey; + const taskKey = `${connectionKey?.projectId ?? ''}:${connectionKey?.connectionId ?? ''}:${this.optionsPart.state.driverId ?? ''}`; + + if (this.authStateTask && this.authStateTaskKey === taskKey) { + return this.authStateTask; + } + + const task = this.loadAuthState(contexts); + this.authStateTask = task; + this.authStateTaskKey = taskKey; + task.then( + () => this.clearAuthStateTask(task), + () => this.clearAuthStateTask(task), + ); + return task; + } + + private async loadAuthState(contexts: IExecutionContextProvider): Promise { const stateContext = contexts.getContext(formStateContext); const info = this.optionsPart.connectionKey ? await this.connectionInfoAuthPropertiesResource.load(this.optionsPart.connectionKey) : null; @@ -51,6 +76,13 @@ export class ConnectionFormOriginInfoFormPart extends FormPart): void { + if (this.authStateTask === task) { + this.authStateTask = undefined; + this.authStateTaskKey = undefined; + } + } + protected override async loader(): Promise {} protected override async saveChanges(): Promise {}