Skip to content

Commit 78ec1a4

Browse files
authored
fix: full refresh on logs page (supabase#37246)
1 parent d9cfc6b commit 78ec1a4

File tree

1 file changed

+8
-7
lines changed
  • apps/studio/pages/project/[ref]/logs

1 file changed

+8
-7
lines changed

apps/studio/pages/project/[ref]/logs/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRouter } from 'next/router'
2-
import { useEffect } from 'react'
2+
import { useContext, useEffect } from 'react'
33

4-
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
4+
import { FeatureFlagContext, LOCAL_STORAGE_KEYS, useParams } from 'common'
55
import { useUnifiedLogsPreview } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
66
import { UnifiedLogs } from 'components/interfaces/UnifiedLogs/UnifiedLogs'
77
import DefaultLayout from 'components/layouts/DefaultLayout'
@@ -13,6 +13,7 @@ import type { NextPageWithLayout } from 'types'
1313
export const LogPage: NextPageWithLayout = () => {
1414
const router = useRouter()
1515
const { ref } = useParams()
16+
const { hasLoaded } = useContext(FeatureFlagContext)
1617
const { isEnabled: isUnifiedLogsEnabled } = useUnifiedLogsPreview()
1718

1819
const [lastVisitedLogsPage] = useLocalStorageQuery(
@@ -21,29 +22,29 @@ export const LogPage: NextPageWithLayout = () => {
2122
)
2223

2324
useEffect(() => {
24-
if (!isUnifiedLogsEnabled) {
25+
if (hasLoaded && !isUnifiedLogsEnabled) {
2526
router.replace(`/project/${ref}/logs/${lastVisitedLogsPage}`)
2627
}
27-
}, [router, lastVisitedLogsPage, ref, isUnifiedLogsEnabled])
28+
}, [router, hasLoaded, lastVisitedLogsPage, ref, isUnifiedLogsEnabled])
2829

2930
// Handle redirects when unified logs preview flag changes
3031
useEffect(() => {
3132
// Only handle redirects if we're currently on a logs page
32-
if (!router.asPath.includes('/logs')) return
33+
if (!router.asPath.includes('/logs') || !hasLoaded) return
3334

3435
if (isUnifiedLogsEnabled) {
3536
// If unified logs preview is enabled and we're not already on the main logs page
3637
if (router.asPath !== `/project/${ref}/logs` && router.asPath.includes('/logs/')) {
3738
router.push(`/project/${ref}/logs`)
3839
}
39-
} else if (!isUnifiedLogsEnabled) {
40+
} else {
4041
// If unified logs preview is disabled and admin flag is also off
4142
// and we're on the main logs page, redirect to explorer
4243
if (router.asPath === `/project/${ref}/logs`) {
4344
router.push(`/project/${ref}/logs/explorer`)
4445
}
4546
}
46-
}, [isUnifiedLogsEnabled, router, ref])
47+
}, [isUnifiedLogsEnabled, router, ref, hasLoaded])
4748

4849
if (isUnifiedLogsEnabled) {
4950
return (

0 commit comments

Comments
 (0)