Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dashboard] improve performance for initial rendering #208050

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { DASHBOARD_GRID_HEIGHT, DASHBOARD_MARGIN_SIZE } from './constants';
import { DashboardGridItem } from './dashboard_grid_item';
import { useLayoutStyles } from './use_layout_styles';

export const DashboardGrid = ({ dashboardContainer }: { dashboardContainer?: HTMLElement }) => {
export const DashboardGrid = ({
dashboardContainerRef,
}: {
dashboardContainerRef?: React.MutableRefObject<HTMLElement | null>;
}) => {
const dashboardApi = useDashboardApi();
const layoutStyles = useLayoutStyles();
const panelRefs = useRef<{ [panelId: string]: React.Ref<HTMLDivElement> }>({});
Expand Down Expand Up @@ -103,11 +107,11 @@ export const DashboardGrid = ({ dashboardContainer }: { dashboardContainer?: HTM
type={type}
setDragHandles={setDragHandles}
appFixedViewport={appFixedViewport}
dashboardContainer={dashboardContainer}
dashboardContainerRef={dashboardContainerRef}
/>
);
},
[appFixedViewport, dashboardApi, dashboardContainer]
[appFixedViewport, dashboardApi, dashboardContainerRef]
);

const memoizedgridLayout = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type DivProps = Pick<React.HTMLAttributes<HTMLDivElement>, 'className' | 'style'

export interface Props extends DivProps {
appFixedViewport?: HTMLElement;
dashboardContainer?: HTMLElement;
dashboardContainerRef?: React.MutableRefObject<HTMLElement | null>;
id: DashboardPanelState['explicitInput']['id'];
index?: number;
type: DashboardPanelState['type'];
Expand All @@ -38,7 +38,7 @@ export const Item = React.forwardRef<HTMLDivElement, Props>(
(
{
appFixedViewport,
dashboardContainer,
dashboardContainerRef,
id,
index,
type,
Expand Down Expand Up @@ -103,7 +103,7 @@ export const Item = React.forwardRef<HTMLDivElement, Props>(
}
}, [id, dashboardApi, scrollToPanelId, highlightPanelId, ref, blurPanel]);

const dashboardContainerTopOffset = dashboardContainer?.offsetTop || 0;
const dashboardContainerTopOffset = dashboardContainerRef?.current?.offsetTop || 0;
const globalNavTopOffset = appFixedViewport?.offsetTop || 0;

const focusStyles = blurPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import { useDashboardApi } from '../../../dashboard_api/use_dashboard_api';
import { useDashboardInternalApi } from '../../../dashboard_api/use_dashboard_internal_api';
import { DashboardEmptyScreen } from '../empty_screen/dashboard_empty_screen';

export const DashboardViewport = ({ dashboardContainer }: { dashboardContainer?: HTMLElement }) => {
export const DashboardViewport = ({
dashboardContainerRef,
}: {
dashboardContainerRef?: React.MutableRefObject<HTMLElement | null>;
}) => {
const dashboardApi = useDashboardApi();
const dashboardInternalApi = useDashboardInternalApi();
const [hasControls, setHasControls] = useState(false);
Expand Down Expand Up @@ -136,7 +140,7 @@ export const DashboardViewport = ({ dashboardContainer }: { dashboardContainer?:
data-description={description}
data-shared-items-count={panelCount}
>
<DashboardGrid dashboardContainer={dashboardContainer} />
<DashboardGrid dashboardContainerRef={dashboardContainerRef} />
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function DashboardRenderer({
onApiAvailable,
}: DashboardRendererProps) {
const dashboardViewport = useRef(null);
const dashboardContainer = useRef(null);
const dashboardContainerRef = useRef<HTMLElement | null>(null);
const [dashboardApi, setDashboardApi] = useState<DashboardApi | undefined>();
const [dashboardInternalApi, setDashboardInternalApi] = useState<
DashboardInternalApi | undefined
Expand Down Expand Up @@ -112,17 +112,13 @@ export function DashboardRenderer({
}

return dashboardApi && dashboardInternalApi ? (
<div className="dashboardContainer" ref={dashboardContainer}>
<div className="dashboardContainer" ref={(e) => (dashboardContainerRef.current = e)}>
<ExitFullScreenButtonKibanaProvider
coreStart={{ chrome: coreServices.chrome, customBranding: coreServices.customBranding }}
>
<DashboardContext.Provider value={dashboardApi}>
<DashboardInternalContext.Provider value={dashboardInternalApi}>
<DashboardViewport
dashboardContainer={
dashboardContainer.current ? dashboardContainer.current : undefined
}
/>
<DashboardViewport dashboardContainerRef={dashboardContainerRef} />
</DashboardInternalContext.Provider>
</DashboardContext.Provider>
</ExitFullScreenButtonKibanaProvider>
Expand Down
Loading