From 04f3c6c41cdca36c51ffcc951c4ff08ebdec65c2 Mon Sep 17 00:00:00 2001 From: "supabase-vercel-tedd[bot]" <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 08:15:41 -0600 Subject: [PATCH] fix(studio): return to the buckets list after deleting a bucket from its page (#53028) ## Problem Deleting a bucket from its own page (`/storage/files/buckets/[bucketId]`) could leave Studio on the deleted bucket's route. The page kept loading and then showed "Failed to fetch buckets" / "Bucket not found". On success, `DeleteBucketModal` called `onClose()` and then `router.push` to the buckets list. On the bucket page, `onClose` clears the `?delete` query param through nuqs, which queues its own shallow push to the current bucket URL. That push could race with the navigation to the list and land back on the deleted bucket. The page then re-rendered with the bucket query already removed from the cache, refetched the missing bucket, and got a 404. ## Solution - On the bucket's own page, the success handler now awaits `router.push` to the buckets list and does not call `onClose`. The modal closes when the page unmounts. When there is no `bucketId` in the route, it still calls `onClose` as before. - Added a component test for deleting from the bucket page. It checks that Studio ends up on `/project//storage/files` and that `onClose` is not called. The test opts out of the global `useParams` stub so the modal reads `bucketId` from the mocked route. It fails without the fix. ## How to verify 1. Open a project, go to Storage > Files, and open any bucket. 2. Choose Edit bucket > Delete bucket, type the bucket name, and confirm. 3. Studio shows the success toast and lands on the buckets list (`/project//storage/files`). The deleted bucket no longer appears there. 4. Studio never shows the deleted bucket's page with a spinner that keeps loading, "Failed to fetch buckets" or "Bucket not found". ## Checks run - `pnpm --filter studio exec vitest run components/interfaces/Storage/FilesBuckets/DeleteBucketModal.test.tsx` (2 passed) - `pnpm turbo run typecheck --filter='...[origin/master]'` - `pnpm turbo run lint --filter='[origin/master]'` - Prettier check on the changed files [FE-4926](https://linear.app/supabase/issue/FE-4926/deleting-a-bucket-leaves-its-page-loading-until-an-error) --------- Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com> --- .../FilesBuckets/DeleteBucketModal.test.tsx | 19 +++++++++++++++++++ .../FilesBuckets/DeleteBucketModal.tsx | 7 +++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.test.tsx b/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.test.tsx index 36bbe0d6632..27a0115ecc5 100644 --- a/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.test.tsx +++ b/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.test.tsx @@ -11,6 +11,10 @@ import { customRender } from '@/tests/lib/custom-render' import { addAPIMock } from '@/tests/lib/msw' import { routerMock } from '@/tests/lib/route-mock' +// Use the real `useParams` (backed by the router mock) instead of the global stub, so the +// modal sees the `bucketId` of the current URL. +vi.mock('common', async (importOriginal) => importOriginal()) + const bucket: Bucket = { id: 'test', name: 'test', @@ -127,4 +131,19 @@ describe(`DeleteBucketModal`, () => { await waitFor(() => expect(onClose).toHaveBeenCalledOnce()) expect(routerMock.asPath).toStrictEqual(`/project/default/storage/files`) }) + + it(`navigates from the deleted bucket's page to the buckets list`, async () => { + routerMock.setCurrentUrl(`/project/default/storage/files/buckets/${bucket.id}?delete=true`) + const onClose = vi.fn() + customRender() + + await userEvent.click(screen.getByRole(`button`, { name: `Open` })) + await screen.findByRole(`dialog`) + + await userEvent.type(screen.getByPlaceholderText(`Type bucket name`), bucket.id) + fireEvent.click(screen.getByRole(`button`, { name: `Delete bucket` })) + + await waitFor(() => expect(routerMock.asPath).toStrictEqual(`/project/default/storage/files`)) + expect(onClose).not.toHaveBeenCalled() + }) }) diff --git a/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.tsx b/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.tsx index 1f8d57b3889..8a135a2c0f6 100644 --- a/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.tsx +++ b/apps/studio/components/interfaces/Storage/FilesBuckets/DeleteBucketModal.tsx @@ -36,8 +36,11 @@ export const DeleteBucketModal = ({ visible, bucket, onClose }: DeleteBucketModa // policy cleanup below (which can be slow) doesn't hold the loading state or block // the success feedback. toast.success(`Successfully deleted bucket ${bucket.id}`) - onClose() - if (bucketId) router.push(`/project/${projectRef}/storage/files`) + if (bucketId) { + await router.push(`/project/${projectRef}/storage/files`) + } else { + onClose() + } if (!project) return console.error('Project is required')