Skip to content

Commit 15d84c3

Browse files
committed
fix(web): prevent overlapping ACP provider reloads
1 parent 9c03c8f commit 15d84c3

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

‎apps/web/src/components/settings/AcpSessionManagementSection.browser.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,25 @@ it.each(["Save", "Disable"])("keeps other provider edits through a %s refetch",
195195
resolveReload = resolve;
196196
});
197197
commands.listProviders.mockReturnValueOnce(reload);
198+
let resolveMutation!: () => void;
199+
const mutation = new Promise<void>((resolve) => {
200+
resolveMutation = resolve;
201+
});
202+
const command = action === "Save" ? commands.setProvider : commands.disableProvider;
203+
command.mockReturnValueOnce(
204+
mutation.then(() => ({
205+
_tag: "Success",
206+
value: action === "Save" ? { configured: true } : { disabled: true },
207+
})),
208+
);
198209
await screen.click(action);
210+
expect(screen.button("Refresh").disabled).toBe(true);
211+
await act(async () => resolveMutation());
212+
for (const button of screen.container.querySelectorAll<HTMLButtonElement>("button")) {
213+
if (button.textContent === "Save" || button.textContent === "Disable") {
214+
expect(button.disabled).toBe(true);
215+
}
216+
}
199217
await userEvent.fill(input("other base URL"), "https://newer.example.test/v1");
200218
await act(async () => resolveReload(response));
201219

‎apps/web/src/components/settings/AcpSessionManagementSection.tsx‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ export function AcpSessionManagementSection(props: {
244244
if (
245245
!readEnvironmentScope(props.environmentId, AuthProvidersManageScope) ||
246246
projectId === null ||
247-
savingProviderId !== null
247+
savingProviderId !== null ||
248+
loadingProviders
248249
)
249250
return;
250251
const draft = providerDrafts[provider.providerId];
@@ -281,7 +282,8 @@ export function AcpSessionManagementSection(props: {
281282
};
282283

283284
const disableConfiguredProvider = async (provider: AcpRegistryConfigurableProvider) => {
284-
if (projectId === null || savingProviderId !== null || provider.required) return;
285+
if (projectId === null || savingProviderId !== null || loadingProviders || provider.required)
286+
return;
285287
const confirmed = await ensureLocalApi().dialogs.confirm(
286288
`Disable ACP provider "${provider.providerId}"?`,
287289
{ variant: "destructive" },
@@ -468,7 +470,9 @@ export function AcpSessionManagementSection(props: {
468470
type="button"
469471
size="xs"
470472
variant="outline"
471-
disabled={!canRead || loadingProviders || projectId === null}
473+
disabled={
474+
!canRead || loadingProviders || savingProviderId !== null || projectId === null
475+
}
472476
onClick={() => void loadProviders()}
473477
>
474478
{loadingProviders ? "Loading" : providers.length === 0 ? "List providers" : "Refresh"}
@@ -534,6 +538,7 @@ export function AcpSessionManagementSection(props: {
534538
disabled={
535539
props.readOnly ||
536540
savingProviderId !== null ||
541+
loadingProviders ||
537542
draft.apiType.length === 0 ||
538543
draft.baseUrl.length === 0
539544
}
@@ -546,7 +551,9 @@ export function AcpSessionManagementSection(props: {
546551
type="button"
547552
size="xs"
548553
variant="ghost-muted"
549-
disabled={props.readOnly || savingProviderId !== null}
554+
disabled={
555+
props.readOnly || savingProviderId !== null || loadingProviders
556+
}
550557
onClick={() => void disableConfiguredProvider(provider)}
551558
>
552559
Disable

0 commit comments

Comments
 (0)