Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions apps/studio/state/storage-explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createContext, PropsWithChildren, useContext, useEffect, useState } fro
import { useLatest } from 'react-use'
import { toast } from 'sonner'
import * as tus from 'tus-js-client'
import { proxy, snapshot, useSnapshot } from 'valtio'
import { proxy, useSnapshot } from 'valtio'

import { createClient, SupabaseClient } from '@supabase/supabase-js'
import { BlobReader, BlobWriter, ZipWriter } from '@zip.js/zip.js'
Expand Down Expand Up @@ -1744,23 +1744,18 @@ export const StorageExplorerStateContextProvider = ({ children }: PropsWithChild
const { serviceKey } = getKeys(apiKeys)
const protocol = settings?.app_config?.protocol ?? 'https'
const endpoint = settings?.app_config?.endpoint
const resumableUploadUrl = `${IS_PLATFORM ? 'https' : protocol}://${endpoint}/storage/v1/upload/resumable`

// [Joshen] JFYI opting with the useEffect here as the storage explorer state was being loaded
// before the project details were ready, hence the store kept returning project ref as undefined
// Can be verified when we're saving the storage explorer preferences into local storage, that ref is undefined
// So the useEffect here is to make sure that the project ref is loaded into the state properly
// Although I'd be keen to re-investigate this to see if we can remove this
useEffect(() => {
const snap = snapshot(stateRef.current)
const hasDataReady = !!project?.ref
const resumableUploadUrl = `${IS_PLATFORM ? 'https' : protocol}://${endpoint}/storage/v1/upload/resumable`

const isDifferentProject = snap.projectRef !== project?.ref
const isDifferentResumableUploadUrl = snap.resumableUploadUrl !== resumableUploadUrl

const serviceApiKey = serviceKey?.api_key ?? 'unknown'

if (!isPaused && hasDataReady && (isDifferentProject || isDifferentResumableUploadUrl)) {
if (!isPaused && hasDataReady) {
const clientEndpoint = `${IS_PLATFORM ? 'https' : protocol}://${endpoint}`
const supabaseClient = createClient(clientEndpoint, serviceApiKey, {
auth: {
Expand All @@ -1786,7 +1781,15 @@ export const StorageExplorerStateContextProvider = ({ children }: PropsWithChild
})
)
}
}, [project?.ref, stateRef, serviceKey?.api_key, isPaused, protocol, endpoint])
}, [
project?.ref,
stateRef,
serviceKey?.api_key,
isPaused,
resumableUploadUrl,
protocol,
endpoint,
])

return (
<StorageExplorerStateContext.Provider value={state}>
Expand Down
Loading