diff --git a/apps/studio/components/grid/SupabaseGrid.utils.ts b/apps/studio/components/grid/SupabaseGrid.utils.ts index 5f6ae0cf5fa..03a62116b72 100644 --- a/apps/studio/components/grid/SupabaseGrid.utils.ts +++ b/apps/studio/components/grid/SupabaseGrid.utils.ts @@ -127,6 +127,8 @@ export function loadTableEditorStateFromLocalStorage( tableName: string, schema?: string | null ): SavedState | undefined { + if (typeof window === 'undefined') return undefined + const storageKey = getStorageKey(STORAGE_KEY_PREFIX, projectRef) const jsonStr = localStorage.getItem(storageKey) if (!jsonStr) return diff --git a/apps/studio/state/table-editor-table.tsx b/apps/studio/state/table-editor-table.tsx index 771d5d4b09e..5176982a1a8 100644 --- a/apps/studio/state/table-editor-table.tsx +++ b/apps/studio/state/table-editor-table.tsx @@ -14,6 +14,17 @@ import { getGridColumns } from 'components/grid/utils/gridColumns' import { Entity } from 'data/table-editor/table-editor-types' import { useTableEditorStateSnapshot } from './table-editor' +const DEFAULT_STATE = { + editable: undefined, + _originalTableRef: undefined, + table: { name: '', schema: '' }, + gridColumns: [], + allRowsSelected: false, + selectedCellPosition: undefined, + updateTable: () => {}, + setEditable: () => {}, +} + export const createTableEditorTableState = ({ projectRef, table: originalTable, @@ -30,17 +41,9 @@ export const createTableEditorTableState = ({ onExpandJSONEditor: (column: string, row: SupaRow) => void onExpandTextEditor: (column: string, row: SupaRow) => void }) => { - if (!originalTable) - return proxy({ - editable, - _originalTableRef: undefined, - table: { name: '', schema: '' }, - gridColumns: [], - updateTable: () => {}, - setEditable: () => {}, - }) - - const table = parseSupaTable(originalTable) + const table = !!originalTable + ? parseSupaTable(originalTable) + : { id: -1, name: '', schema: undefined, columns: [], comment: undefined, estimateRowCount: 0 } const savedState = loadTableEditorStateFromLocalStorage(projectRef, table.name, table.schema) const gridColumns = getInitialGridColumns( @@ -63,7 +66,7 @@ export const createTableEditorTableState = ({ * Used for tracking changes to the table * Do not use outside of table-editor-table.tsx */ - _originalTableRef: ref(originalTable), + _originalTableRef: ref(originalTable ?? {}), updateTable: (table: Entity) => { const supaTable = parseSupaTable(table)