@@ -28,6 +28,7 @@ import PanelEvent from './PanelEvent';
2828import { GLPropTypes , useListener } from './layout' ;
2929import { getDashboardData , updateDashboardData } from './redux' ;
3030import {
31+ isWrappedComponent ,
3132 PanelComponentType ,
3233 PanelDehydrateFunction ,
3334 PanelHydrateFunction ,
@@ -118,24 +119,49 @@ export function DashboardLayout({
118119 componentDehydrate
119120 ) ;
120121
121- function wrappedComponent ( props : PanelProps ) : JSX . Element {
122- const CType = componentType ;
122+ function wrappedComponent (
123+ props : PanelProps ,
124+ ref : React . Ref < unknown >
125+ ) : JSX . Element {
126+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
127+ const CType = componentType as any ;
123128 const PanelWrapperType = panelWrapper ;
124129
130+ /*
131+ Checking for class components will let us silence the React warning
132+ about assigning refs to function components not using forwardRef.
133+ The ref is used to detect changes to class component state so we
134+ can track changes to panelState. We should opt for more explicit
135+ state changes in the future and in functional components.
136+ */
137+ const isClassComponent =
138+ ( isWrappedComponent ( CType ) &&
139+ CType . WrappedComponent . prototype != null &&
140+ CType . WrappedComponent . prototype . isReactComponent != null ) ||
141+ ( CType . prototype != null && CType . prototype . isReactComponent != null ) ;
142+
125143 // Props supplied by GoldenLayout
126144 const { glContainer, glEventHub } = props ;
127145 return (
128146 < PanelErrorBoundary glContainer = { glContainer } glEventHub = { glEventHub } >
129147 { /* eslint-disable-next-line react/jsx-props-no-spreading */ }
130148 < PanelWrapperType { ...props } >
131- { /* eslint-disable-next-line react/jsx-props-no-spreading */ }
132- < CType { ...props } />
149+ { isClassComponent ? (
150+ // eslint-disable-next-line react/jsx-props-no-spreading
151+ < CType { ...props } ref = { ref } />
152+ ) : (
153+ // eslint-disable-next-line react/jsx-props-no-spreading
154+ < CType { ...props } />
155+ ) }
133156 </ PanelWrapperType >
134157 </ PanelErrorBoundary >
135158 ) ;
136159 }
137160
138- const cleanup = layout . registerComponent ( name , wrappedComponent ) ;
161+ const cleanup = layout . registerComponent (
162+ name ,
163+ React . forwardRef ( wrappedComponent )
164+ ) ;
139165 hydrateMap . set ( name , componentHydrate ) ;
140166 dehydrateMap . set ( name , componentDehydrate ) ;
141167 return cleanup ;
0 commit comments