11import { 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'
55import { useUnifiedLogsPreview } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
66import { UnifiedLogs } from 'components/interfaces/UnifiedLogs/UnifiedLogs'
77import DefaultLayout from 'components/layouts/DefaultLayout'
@@ -13,6 +13,7 @@ import type { NextPageWithLayout } from 'types'
1313export 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