diff --git a/studio/components/layouts/SQLEditorLayout/QueryItem.tsx b/studio/components/layouts/SQLEditorLayout/QueryItem.tsx index 7472e6ab7eb..7571d5f2c9b 100644 --- a/studio/components/layouts/SQLEditorLayout/QueryItem.tsx +++ b/studio/components/layouts/SQLEditorLayout/QueryItem.tsx @@ -85,7 +85,7 @@ const QueryItemActions = observer(({ tabInfo }: { tabInfo: SqlSnippet }) => { try { await deleteContent({ projectRef: ref, id }) - const existingSnippetIds = Object.keys(snap.snippets) + const existingSnippetIds = Object.keys(snap.snippets).filter((x) => x !== id) if (existingSnippetIds.length === 0) { router.push(`/project/${ref}/sql`) } else { diff --git a/studio/state/sql-editor.ts b/studio/state/sql-editor.ts index c7cc46f9aa9..4ce5d62fed8 100644 --- a/studio/state/sql-editor.ts +++ b/studio/state/sql-editor.ts @@ -68,7 +68,10 @@ export const sqlEditorState = proxy({ } sqlEditorState.results[snippet.id] = [] sqlEditorState.savingStates[snippet.id] = 'IDLE' - if (!sqlEditorState.orders[projectRef].includes(snippet.id)) { + if ( + sqlEditorState.orders[projectRef] !== undefined && + !sqlEditorState.orders[projectRef].includes(snippet.id) + ) { sqlEditorState.orders[projectRef].unshift(snippet.id) } if (isNew) {