1
1
import { EuiResizableContainer } from '@elastic/eui'
2
- import React , { useCallback , useEffect , useState } from 'react'
2
+ import React , { useCallback , useEffect , useRef , useState } from 'react'
3
3
import { useDispatch , useSelector } from 'react-redux'
4
- import { useParams } from 'react-router-dom'
4
+ import { useLocation , useParams } from 'react-router-dom'
5
5
import cx from 'classnames'
6
6
7
7
import { setInitialAnalyticsSettings } from 'uiSrc/slices/analytics/settings'
@@ -34,6 +34,7 @@ import { setClusterDetailsInitialState } from 'uiSrc/slices/analytics/clusterDet
34
34
import { setDatabaseAnalysisInitialState } from 'uiSrc/slices/analytics/dbAnalysis'
35
35
import { resetRedisearchKeysData , setRedisearchInitialState } from 'uiSrc/slices/browser/redisearch'
36
36
import { setTriggeredFunctionsInitialState } from 'uiSrc/slices/triggeredFunctions/triggeredFunctions'
37
+ import { getPageName } from 'uiSrc/utils/routing'
37
38
import InstancePageRouter from './InstancePageRouter'
38
39
39
40
import styles from './styles.module.scss'
@@ -66,12 +67,16 @@ const InstancePage = ({ routes = [] }: Props) => {
66
67
const [ isShouldChildrenRerender , setIsShouldChildrenRerender ] = useState ( false )
67
68
68
69
const dispatch = useDispatch ( )
70
+ const { pathname } = useLocation ( )
71
+
69
72
const { instanceId : connectionInstanceId } = useParams < { instanceId : string } > ( )
70
73
const { isShowCli, isShowHelper } = useSelector ( cliSettingsSelector )
71
74
const { data : modulesData } = useSelector ( instancesSelector )
72
75
const { isShowMonitor } = useSelector ( monitorSelector )
73
76
const { contextInstanceId } = useSelector ( appContextSelector )
74
77
78
+ const lastPageRef = useRef < string > ( )
79
+
75
80
const isShowBottomGroup = isShowCli || isShowHelper || isShowMonitor
76
81
77
82
useEffect ( ( ) => {
@@ -82,9 +87,10 @@ const InstancePage = ({ routes = [] }: Props) => {
82
87
dispatch ( fetchConnectedInstanceInfoAction ( connectionInstanceId ) )
83
88
84
89
if ( contextInstanceId && contextInstanceId !== connectionInstanceId ) {
85
- // rerender children from scratch to clear all component states
86
- setIsShouldChildrenRerender ( true )
87
- requestAnimationFrame ( ( ) => setIsShouldChildrenRerender ( false ) )
90
+ // rerender children only if the same page from scratch to clear all component states
91
+ if ( lastPageRef . current === getPageName ( connectionInstanceId , pathname ) ) {
92
+ setIsShouldChildrenRerender ( true )
93
+ }
88
94
89
95
resetContext ( )
90
96
}
@@ -93,6 +99,14 @@ const InstancePage = ({ routes = [] }: Props) => {
93
99
dispatch ( setDbConfig ( localStorageService . get ( BrowserStorageItem . dbConfig + connectionInstanceId ) ) )
94
100
} , [ connectionInstanceId ] )
95
101
102
+ useEffect ( ( ) => {
103
+ lastPageRef . current = getPageName ( connectionInstanceId , pathname )
104
+ } , [ pathname ] )
105
+
106
+ useEffect ( ( ) => {
107
+ if ( isShouldChildrenRerender ) setIsShouldChildrenRerender ( false )
108
+ } , [ isShouldChildrenRerender ] )
109
+
96
110
useEffect ( ( ) => ( ) => {
97
111
setSizes ( ( prevSizes : ResizablePanelSize ) => {
98
112
localStorageService . set ( BrowserStorageItem . cliResizableContainer , {
0 commit comments