Fix: SQL Editor browser back button navigation (#43043)

## Problem
The SQL Editor had a browser navigation issue where pressing the back
button would get stuck in a redirect loop between `/sql` and `/sql/new`,
making it difficult to navigate away from the SQL Editor using standard
browser controls.

## Solution
Changed automatic redirects from `router.push()` to `router.replace()`
in the SQL Editor routing logic.
This prevents adding unwanted history entries during automatic
navigation, allowing the back button to work as expected.

## Related
- Closes https://github.com/supabase/supabase/issues/43035
This commit is contained in:
Vaibhav authored and GitHub committed 2026-02-21 17:43:08 +00:00
1 parent 571e0603c0
commit f8419ef9ae
2 files changed
+5 -5

No files matched your search

+2 -2
View File
@@ -69,7 +69,7 @@ const SqlEditor: NextPageWithLayout = () => {
snapV2.setSnippet(ref, data as unknown as SnippetWithContent)
} else {
setLastVisitedSnippet(undefined)
router.push(`/project/${ref}/sql/new`)
router.replace(`/project/${ref}/sql/new`)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -84,7 +84,7 @@ const SqlEditor: NextPageWithLayout = () => {
content === undefined
) {
const snippet = allSnippets.find((snippet) => snippet.id === history.sql)
if (snippet !== undefined) router.push(`/project/${ref}/sql/${history.sql}`)
if (snippet !== undefined) router.replace(`/project/${ref}/sql/${history.sql}`)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id, allSnippets, content])
@@ -23,14 +23,14 @@ const SQLEditorIndexPage: NextPageWithLayout = () => {
const lastOpenedTab = history.sql
const lastTabId = store.openTabs.find((id) => store.tabsMap[id]?.type === 'sql')
if (lastOpenedTab !== undefined) {
router.push(`/project/${projectRef}/sql/${history.sql}`)
router.replace(`/project/${projectRef}/sql/${history.sql}`)
} else if (lastTabId) {
const lastTab = store.tabsMap[lastTabId]
if (lastTab) {
router.push(`/project/${projectRef}/sql/${lastTab.id.replace('sql-', '')}`)
router.replace(`/project/${projectRef}/sql/${lastTab.id.replace('sql-', '')}`)
}
} else {
router.push(`/project/${projectRef}/sql/new`)
router.replace(`/project/${projectRef}/sql/new`)
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps