Skip to content

Commit 478ca3c

Browse files
authored
Fix storage store init when switching projects (supabase#37384)
1 parent 57cd26a commit 478ca3c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

apps/studio/state/storage-explorer.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createContext, PropsWithChildren, useContext, useEffect, useState } fro
33
import { useLatest } from 'react-use'
44
import { toast } from 'sonner'
55
import * as tus from 'tus-js-client'
6-
import { proxy, snapshot, useSnapshot } from 'valtio'
6+
import { proxy, useSnapshot } from 'valtio'
77

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

17481749
// [Joshen] JFYI opting with the useEffect here as the storage explorer state was being loaded
17491750
// before the project details were ready, hence the store kept returning project ref as undefined
17501751
// Can be verified when we're saving the storage explorer preferences into local storage, that ref is undefined
17511752
// So the useEffect here is to make sure that the project ref is loaded into the state properly
17521753
// Although I'd be keen to re-investigate this to see if we can remove this
17531754
useEffect(() => {
1754-
const snap = snapshot(stateRef.current)
17551755
const hasDataReady = !!project?.ref
1756-
const resumableUploadUrl = `${IS_PLATFORM ? 'https' : protocol}://${endpoint}/storage/v1/upload/resumable`
1757-
1758-
const isDifferentProject = snap.projectRef !== project?.ref
1759-
const isDifferentResumableUploadUrl = snap.resumableUploadUrl !== resumableUploadUrl
1760-
17611756
const serviceApiKey = serviceKey?.api_key ?? 'unknown'
17621757

1763-
if (!isPaused && hasDataReady && (isDifferentProject || isDifferentResumableUploadUrl)) {
1758+
if (!isPaused && hasDataReady) {
17641759
const clientEndpoint = `${IS_PLATFORM ? 'https' : protocol}://${endpoint}`
17651760
const supabaseClient = createClient(clientEndpoint, serviceApiKey, {
17661761
auth: {
@@ -1786,7 +1781,15 @@ export const StorageExplorerStateContextProvider = ({ children }: PropsWithChild
17861781
})
17871782
)
17881783
}
1789-
}, [project?.ref, stateRef, serviceKey?.api_key, isPaused, protocol, endpoint])
1784+
}, [
1785+
project?.ref,
1786+
stateRef,
1787+
serviceKey?.api_key,
1788+
isPaused,
1789+
resumableUploadUrl,
1790+
protocol,
1791+
endpoint,
1792+
])
17901793

17911794
return (
17921795
<StorageExplorerStateContext.Provider value={state}>

0 commit comments

Comments
 (0)