@@ -7,6 +7,7 @@ import History, {
77 type HistoryEntry ,
88 type HistoryEntryLocation
99} from "../../../../history/History" ;
10+ import { usePrevious } from "../../../../hooks/usePrevious" ;
1011import {
1112 digmaApi ,
1213 useGetSpanInfoQuery
@@ -70,18 +71,10 @@ export const RepositorySidebarOverlay = ({
7071 ) ;
7172 const { resetInsights, resetAssets, resetGlobalErrors } = useStore . getState ( ) ;
7273 const dispatch = useAdminDispatch ( ) ;
73- const [ history ] = useState (
74- ( ) =>
75- new History < RepositorySidebarHistoryState > ( [
76- {
77- location : window . location ,
78- state : {
79- spanCodeObjectId : currentSpanCodeObjectId ,
80- tabLocation : currentTabLocation
81- }
82- }
83- ] )
74+ const [ history , setHistory ] = useState (
75+ ( ) => new History < RepositorySidebarHistoryState > ( [ ] )
8476 ) ;
77+ const previousIsSidebarOpen = usePrevious ( isSidebarOpen ) ;
8578
8679 const { data : spanInfo } = useGetSpanInfoQuery (
8780 { spanCodeObjectId : currentSpanCodeObjectId ?? "" } ,
@@ -172,17 +165,21 @@ export const RepositorySidebarOverlay = ({
172165 resetInsights ( ) ;
173166 resetAssets ( ) ;
174167 resetGlobalErrors ( ) ;
175- history . clear ( ) ;
176- setCurrentTabLocation ( initialTabLocation ) ;
177168 setCurrentSpanCodeObjectId ( undefined ) ;
169+ setCurrentTabLocation ( initialTabLocation ) ;
178170 onSidebarClose ( ) ;
171+ } , [ dispatch , onSidebarClose , resetAssets , resetGlobalErrors , resetInsights ] ) ;
172+
173+ // Reset history on sidebar open
174+ useEffect ( ( ) => {
175+ if ( ! previousIsSidebarOpen && isSidebarOpen ) {
176+ setHistory ( new History < RepositorySidebarHistoryState > ( [ ] ) ) ;
177+ }
179178 } , [
180- dispatch ,
181- onSidebarClose ,
182- resetAssets ,
183- resetGlobalErrors ,
184- resetInsights ,
185- history
179+ previousIsSidebarOpen ,
180+ isSidebarOpen ,
181+ currentSpanCodeObjectId ,
182+ currentTabLocation
186183 ] ) ;
187184
188185 useEffect ( ( ) => {
0 commit comments