diff --git a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx index 4af5f780c47..cf56d8ac7e0 100644 --- a/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx +++ b/apps/studio/components/interfaces/DiskManagement/DiskManagementForm.tsx @@ -375,14 +375,17 @@ export function DiskManagementForm({ // Apply the recommendation only after the sheet's close lifecycle has completed. useEffect(() => { - if (!recommendedCompute || !isSuccess) return + // The compute add-on supplies the option. Keep the recommendation pending + // until disk attributes have initialised the form, so a later reset cannot + // overwrite it. Other infrastructure requests are unrelated to this handoff. + if (!recommendedCompute || !isAddonsSuccess) return form.setValue('computeSize', recommendedCompute, { shouldDirty: true, shouldValidate: true, }) void form.trigger(['provisionedIOPS', 'throughput']) - onRecommendedComputeApplied?.() + if (isDiskAttributesSuccess) onRecommendedComputeApplied?.() const element = computeSettingsRef.current if (!element) return @@ -404,7 +407,8 @@ export function DiskManagementForm({ mainScrollContainer.scrollTo({ top: Math.max(0, top), behavior: 'smooth' }) }, [ form, - isSuccess, + isAddonsSuccess, + isDiskAttributesSuccess, mainScrollContainer, onRecommendedComputeApplied, recommendedCompute, diff --git a/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx new file mode 100644 index 00000000000..5775b441656 --- /dev/null +++ b/apps/studio/tests/components/Settings/Infrastructure/AddReadReplicaSheet.test.tsx @@ -0,0 +1,29 @@ +import { screen, waitFor } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import { describe, expect, test, vi } from 'vitest' + +import { AddReadReplicaSheet } from '@/components/interfaces/Settings/Infrastructure/ReadReplicas/AddReadReplicaSheet' +import { customRender } from '@/tests/lib/custom-render' + +vi.mock('@/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaForm', () => ({ + ReadReplicaForm: ({ onRecommendCompute }: { onRecommendCompute: (size: 'ci_small') => void }) => ( + + ), +})) + +describe('AddReadReplicaSheet', () => { + test('hands the recommendation off after closing the sheet', async () => { + const user = userEvent.setup() + const onRecommendCompute = vi.fn() + + customRender(, { + nuqs: { searchParams: { addReplica: 'true' } }, + }) + + await user.click(screen.getByRole('button', { name: 'Change to Small compute' })) + + await waitFor(() => expect(onRecommendCompute).toHaveBeenCalledWith('ci_small')) + }) +})