@@ -32,6 +32,7 @@ import {
3232 useParentFlyoutSize ,
3333 useCurrentSession ,
3434} from './hooks' ;
35+ import { useIsFlyoutRegistered } from './selectors' ;
3536import { EuiFlyoutLevel } from './types' ;
3637import {
3738 createValidationErrorMessage ,
@@ -83,14 +84,8 @@ export const EuiManagedFlyout = ({
8384 const flyoutId = useFlyoutId ( id ) ;
8485 const flyoutRef = useRef < HTMLDivElement > ( null ) ;
8586
86- const {
87- addFlyout,
88- closeFlyout,
89- setFlyoutWidth,
90- goBack,
91- getHistoryItems,
92- state,
93- } = useFlyoutManager ( ) ;
87+ const { addFlyout, closeFlyout, setFlyoutWidth, goBack, getHistoryItems } =
88+ useFlyoutManager ( ) ;
9489 const parentSize = useParentFlyoutSize ( flyoutId ) ;
9590 const layoutMode = useFlyoutLayoutMode ( ) ;
9691 const styles = useEuiMemoizedStyles ( euiManagedFlyoutStyles ) ;
@@ -125,6 +120,7 @@ export const EuiManagedFlyout = ({
125120
126121 const isActive = useIsFlyoutActive ( flyoutId ) ;
127122 const currentSession = useCurrentSession ( ) ;
123+ const flyoutExistsInManager = useIsFlyoutRegistered ( flyoutId ) ;
128124
129125 // Stabilize the onClose callback
130126 const onCloseCallbackRef = useRef < ( ( e ?: CloseEvent ) => void ) | undefined > ( ) ;
@@ -156,10 +152,6 @@ export const EuiManagedFlyout = ({
156152 // Detect when flyout has been removed from manager state (e.g., via Back button)
157153 // and trigger onClose callback to notify the parent component
158154 useEffect ( ( ) => {
159- const flyoutExistsInManager = state . flyouts . some (
160- ( f ) => f . flyoutId === flyoutId
161- ) ;
162-
163155 if ( isOpen && flyoutExistsInManager ) {
164156 wasRegisteredRef . current = true ;
165157 }
@@ -170,7 +162,7 @@ export const EuiManagedFlyout = ({
170162 onCloseCallbackRef . current ?.( new MouseEvent ( 'navigation' ) ) ;
171163 wasRegisteredRef . current = false ; // Reset to avoid repeated calls
172164 }
173- } , [ state . flyouts , isOpen , flyoutId ] ) ;
165+ } , [ flyoutExistsInManager , isOpen , flyoutId ] ) ;
174166
175167 // Monitor current session changes and fire onActive callback when this flyout becomes active
176168 useEffect ( ( ) => {
0 commit comments