Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

clear table editor state loaded ids on ref change

Alaister Youngb096e8bcfb1b
diff --git a/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx b/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx
index 6035b2dfef5..5af32a7110e 100644
--- a/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx
+++ b/studio/components/layouts/TableEditorLayout/TableEditorLayout.tsx
@@ -8,6 +8,7 @@ import { checkPermissions, useStore } from 'hooks'
import { useParams } from 'common/hooks'
import { Entity } from 'data/entity-types/entity-type-query'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
+import { useIsTableLoaded, useTableEditorStateSnapshot } from 'state/table-editor'
import ProjectLayout from '../ProjectLayout/ProjectLayout'
import TableEditorMenu from './TableEditorMenu'
import NoPermission from 'components/ui/NoPermission'
@@ -15,7 +16,6 @@ import useEntityType from 'hooks/misc/useEntityType'
import Connecting from 'components/ui/Loading/Loading'
import useLatest from 'hooks/misc/useLatest'
import useTableRowsPrefetchWrapper from './TableEditorLayout.utils'
-import { useIsTableLoaded, useTableEditorStateSnapshot } from 'state/table-editor'
export interface TableEditorLayoutProps {
selectedSchema?: string
diff --git a/studio/state/table-editor.ts b/studio/state/table-editor.ts
index f95c87cb909..99fe3309946 100644
--- a/studio/state/table-editor.ts
+++ b/studio/state/table-editor.ts
@@ -2,17 +2,15 @@ import { proxy, snapshot, useSnapshot } from 'valtio'
import { proxySet } from 'valtio/utils'
export const tableEditorState = proxy({
- loadedIds: {} as {
- [key: string]: Set<number>
- },
+ projectRef: undefined as undefined | string,
+ loadedIds: proxySet<number>([]),
addLoadedId: (ref: string, id: number) => {
- if (!tableEditorState.loadedIds[ref]) {
- tableEditorState.loadedIds[ref] = proxySet<number>([])
+ if (ref !== tableEditorState.projectRef) {
+ tableEditorState.loadedIds.clear()
+ tableEditorState.projectRef = ref
}
- tableEditorState.loadedIds[ref].add(id)
- },
- clearLoadedIdsForProject: (ref: string) => {
- tableEditorState.loadedIds[ref] = proxySet<number>([])
+
+ tableEditorState.loadedIds.add(id)
},
})
@@ -25,5 +23,6 @@ export const useIsTableLoaded = (ref?: string, id?: number) => {
const snap = useTableEditorStateSnapshot()
if (!ref || !id) return false
- return snap.loadedIds[ref]?.has(id) ?? false
+ if (ref !== snap.projectRef) return false
+ return snap.loadedIds.has(id)
}