From 444337da88882dd56fe7a287b329f724a6abd324 Mon Sep 17 00:00:00 2001 From: Matthew Runyon Date: Tue, 2 Apr 2024 15:51:35 -0500 Subject: [PATCH] fix: Dashboard onLayoutInitialized not firing if config is empty --- packages/dashboard/src/DashboardLayout.tsx | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/dashboard/src/DashboardLayout.tsx b/packages/dashboard/src/DashboardLayout.tsx index d7b899958a..615dda3d69 100644 --- a/packages/dashboard/src/DashboardLayout.tsx +++ b/packages/dashboard/src/DashboardLayout.tsx @@ -97,11 +97,15 @@ export function DashboardLayout({ const [initialClosedPanels] = useState( (data as DashboardData)?.closed ?? [] ); - const [isDashboardInitialized, setIsDashboardInitialized] = useState(false); const [layoutChildren, setLayoutChildren] = useState( layout.getReactChildren() ); + // Fire only once after the layout is mounted + // This should ensure DashboardPlugins have been mounted + // eslint-disable-next-line react-hooks/exhaustive-deps + useEffect(() => onLayoutInitialized(), []); + const hydrateMap = useMemo(() => new Map(), []); const dehydrateMap = useMemo(() => new Map(), []); const registerComponent = useCallback( @@ -201,11 +205,6 @@ export function DashboardLayout({ // we risk the last saved state being one without that panel in the layout entirely if (isItemDragging) return; - if (!isDashboardInitialized) { - onLayoutInitialized(); - setIsDashboardInitialized(true); - } - const glConfig = layout.toConfig(); const contentConfig = glConfig.content; const dehydratedLayoutConfig = LayoutUtils.dehydrateLayoutConfig( @@ -232,15 +231,7 @@ export function DashboardLayout({ setLayoutChildren(layout.getReactChildren()); } - }, [ - dehydrateComponent, - isDashboardInitialized, - isItemDragging, - lastConfig, - layout, - onLayoutChange, - onLayoutInitialized, - ]); + }, [dehydrateComponent, isItemDragging, lastConfig, layout, onLayoutChange]); const handleLayoutItemPickedUp = useCallback( (component: Container) => {