perf(board): lift integration query to SectionContent

Avoid N identical useQuery hooks by fetching integrations once
at the parent and passing them as a prop to each WidgetHoverOverlay.
This commit is contained in:
Thomas Camlong committed 2026-06-07 10:40:35 +02:00
1 parent 4cf41f2c4c
commit 93ce4e4a1b
2 files changed
+11 -6

No files matched your search

@@ -2,7 +2,7 @@
import { Avatar, Group, Text, Tooltip } from "@mantine/core"; import { Avatar, Group, Text, Tooltip } from "@mantine/core";
import { clientApi } from "@homarr/api/client"; import type { RouterOutputs } from "@homarr/api";
import { useEditMode } from "@homarr/boards/edit-mode"; import { useEditMode } from "@homarr/boards/edit-mode";
import { getIconUrl } from "@homarr/definitions"; import { getIconUrl } from "@homarr/definitions";
import { useSettings } from "@homarr/settings"; import { useSettings } from "@homarr/settings";
@@ -16,13 +16,13 @@ import classes from "./widget-hover-overlay.module.css";
interface WidgetHoverOverlayProps { interface WidgetHoverOverlayProps {
item: SectionItem; item: SectionItem;
integrations: RouterOutputs["integration"]["all"] | undefined;
} }
export const WidgetHoverOverlay = ({ item }: WidgetHoverOverlayProps) => { export const WidgetHoverOverlay = ({ item, integrations }: WidgetHoverOverlayProps) => {
const [isEditMode] = useEditMode(); const [isEditMode] = useEditMode();
const settings = useSettings(); const settings = useSettings();
const t = useI18n(); const t = useI18n();
const { data: integrations } = clientApi.integration.all.useQuery();
const { definition } = widgetImports[item.kind]; const { definition } = widgetImports[item.kind];
const WidgetIcon = definition.icon; const WidgetIcon = definition.icon;
@@ -2,6 +2,9 @@ import { useMemo } from "react";
import type { GridItemHTMLElement } from "@homarr/gridstack"; import type { GridItemHTMLElement } from "@homarr/gridstack";
import type { RouterOutputs } from "@homarr/api";
import { clientApi } from "@homarr/api/client";
import type { DynamicSectionItem, SectionItem } from "~/app/[locale]/boards/_types"; import type { DynamicSectionItem, SectionItem } from "~/app/[locale]/boards/_types";
import { BoardItemContent } from "../items/item-content"; import { BoardItemContent } from "../items/item-content";
import { WidgetHoverOverlay } from "../items/widget-hover-overlay"; import { WidgetHoverOverlay } from "../items/widget-hover-overlay";
@@ -12,6 +15,7 @@ import { useSectionItems } from "./use-section-items";
export const SectionContent = () => { export const SectionContent = () => {
const { innerSections, items, refs } = useSectionContext(); const { innerSections, items, refs } = useSectionContext();
const { data: integrations } = clientApi.integration.all.useQuery();
/** /**
* IMPORTANT: THE ORDER OF THE BELOW ITEMS HAS TO MATCH THE ORDER OF * IMPORTANT: THE ORDER OF THE BELOW ITEMS HAS TO MATCH THE ORDER OF
@@ -31,7 +35,7 @@ export const SectionContent = () => {
return ( return (
<> <>
{sortedItems.map((item) => ( {sortedItems.map((item) => (
<Item key={item.id} item={item} innerRef={refs.items.current[item.id]} /> <Item key={item.id} item={item} innerRef={refs.items.current[item.id]} integrations={integrations} />
))} ))}
</> </>
); );
@@ -40,9 +44,10 @@ export const SectionContent = () => {
interface ItemProps { interface ItemProps {
item: DynamicSectionItem | SectionItem; item: DynamicSectionItem | SectionItem;
innerRef: React.RefObject<GridItemHTMLElement | null> | undefined; innerRef: React.RefObject<GridItemHTMLElement | null> | undefined;
integrations: RouterOutputs["integration"]["all"] | undefined;
} }
const Item = ({ item, innerRef }: ItemProps) => { const Item = ({ item, innerRef, integrations }: ItemProps) => {
const minWidth = useMinSize(item, "x"); const minWidth = useMinSize(item, "x");
const minHeight = useMinSize(item, "y"); const minHeight = useMinSize(item, "y");
return ( return (
@@ -59,7 +64,7 @@ const Item = ({ item, innerRef }: ItemProps) => {
minWidth={minWidth} minWidth={minWidth}
minHeight={minHeight} minHeight={minHeight}
> >
{item.type === "item" && item.kind !== "app" && <WidgetHoverOverlay item={item} />} {item.type === "item" && item.kind !== "app" && <WidgetHoverOverlay item={item} integrations={integrations} />}
{item.type === "item" ? <BoardItemContent item={item} /> : <BoardDynamicSection section={item} />} {item.type === "item" ? <BoardItemContent item={item} /> : <BoardDynamicSection section={item} />}
</GridStackItem> </GridStackItem>
); );