mirror of
https://github.com/supabase/supabase.git
synced 2026-12-05 07:59:03 +00:00
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/<ref>/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/<ref>/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>
This commit is contained in:
1 parent
bdecc0892c
commit
04f3c6c41c
2 files changed
+24
-2
No files matched your search
@@ -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<typeof import('common')>())
|
||||
|
||||
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(<Page onClose={onClose} />)
|
||||
|
||||
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()
|
||||
})
|
||||
})
|
||||
@@ -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')
|
||||
|
||||
|
||||
Reference in new issue
Block a user