From 040f1059467851b0cc090c289efa2a06ffea8b1c Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Tue, 11 Aug 2026 09:37:48 +0200 Subject: [PATCH] perf(widgets): share the off-screen row primitive, and apply it to the data-driven lists Extracts the media-releases fix into packages/widgets/src/common/offscreen-rows.ts and applies it to the remaining widgets whose list length is decided by remote data rather than by the tile: rssFeed, notifications and the calendar event list. Images in those lists also get loading="lazy" - the rss cards carry two each, a backdrop and a poster. The measured basis, from media-releases where the pattern was found: image requests 135 -> 55 (-59%) layout objects 8346 -> 5117 (-41%) Scope was chosen deliberately rather than applied everywhere. 26 widgets use ScrollArea, but on the measured board only two rendered more than their tile could show, and content-visibility is not free: it costs a little containment work, and on content that measures itself - charts, editors - skipping layout can be actively wrong. The widgets changed here are the ones where overdraw is a function of how much data an integration returns, so a user with a busier instance hits it even though this board does not. Chart and fixed-size widgets are deliberately left alone. Honest scope note: unlike the media-releases change, these three are NOT measured. On the test board rssFeed renders 7 nodes and the calendar's 7 rows fit their tile, so there is nothing to improve here to observe - the benefit only appears with more data than this backup has. They are typechecked and lint-clean. docs/perf/NEXT-STEPS.md tracks them alongside the media-requests change as pending verification. A duplicate `style` prop on the notifications Card was caught by typecheck and merged rather than left to override the existing colour and text-decoration styles. --- .../src/calendar/calendar-event-list.tsx | 4 ++- packages/widgets/src/common/offscreen-rows.ts | 31 +++++++++++++++++++ .../widgets/src/notifications/component.tsx | 3 +- packages/widgets/src/rssFeed/component.tsx | 6 ++-- 4 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 packages/widgets/src/common/offscreen-rows.ts diff --git a/packages/widgets/src/calendar/calendar-event-list.tsx b/packages/widgets/src/calendar/calendar-event-list.tsx index 992da9d71..8b321d367 100644 --- a/packages/widgets/src/calendar/calendar-event-list.tsx +++ b/packages/widgets/src/calendar/calendar-event-list.tsx @@ -19,6 +19,7 @@ import type { CalendarEvent } from "@homarr/integrations/types"; import { useI18n } from "@homarr/translation/client"; import classes from "./calendar-event-list.module.css"; +import { offscreenRowStyle } from "../common/offscreen-rows"; interface CalendarEventListProps { events: CalendarEvent[]; @@ -40,11 +41,12 @@ export const CalendarEventList = ({ events }: CalendarEventListProps) => { > {events.map((event, eventIndex) => ( - + {event.image !== null && ( 55 (-59%) + * layout objects 8346 -> 5117 (-41%) + * + * `content-visibility: auto` lets the browser skip all of that for a row that is scrolled out of + * view. Nothing leaves the DOM, so scrolling, keyboard navigation and in-page search behave exactly + * as before — this is not virtualisation. + * + * `contain-intrinsic-size` supplies a placeholder height for skipped rows. Without it the scrollbar + * jumps as rows enter and leave, because a skipped row would otherwise measure zero. Pass the + * approximate row height; being wrong only affects scrollbar smoothness, not correctness. + * + * Only worth applying to a list whose length is driven by remote data. On a list that always fits its + * tile the containment costs a little and saves nothing, and on non-list content — charts, editors, + * anything that measures itself — skipping layout can be actively wrong. + */ +export const offscreenRowStyle = (approximateRowHeight: number): CSSProperties => ({ + contentVisibility: "auto", + containIntrinsicSize: `auto ${approximateRowHeight}px`, +}); diff --git a/packages/widgets/src/notifications/component.tsx b/packages/widgets/src/notifications/component.tsx index 3b04393d0..e36fe08d8 100644 --- a/packages/widgets/src/notifications/component.tsx +++ b/packages/widgets/src/notifications/component.tsx @@ -10,6 +10,7 @@ import { useTimeAgo } from "@homarr/common"; import { useScopedI18n } from "@homarr/translation/client"; import type { WidgetComponentProps } from "../definition"; +import { offscreenRowStyle } from "../common/offscreen-rows"; export default function NotificationsWidget({ options, integrationIds }: WidgetComponentProps<"notifications">) { const { data: notificationIntegrations = [] } = clientApi.widget.notifications.getNotifications.useQuery({ @@ -43,7 +44,7 @@ export default function NotificationsWidget({ options, integrationIds }: WidgetC radius={board.itemRadius} w="100%" p="sm" - style={{ color: "inherit", textDecoration: "none" }} + style={{ color: "inherit", textDecoration: "none", ...offscreenRowStyle(72) }} > {!options.hideLogos && notification.source?.iconUrl && ( diff --git a/packages/widgets/src/rssFeed/component.tsx b/packages/widgets/src/rssFeed/component.tsx index 626f87328..dc0952bf5 100644 --- a/packages/widgets/src/rssFeed/component.tsx +++ b/packages/widgets/src/rssFeed/component.tsx @@ -10,6 +10,7 @@ import { useRequiredBoard } from "@homarr/boards/context"; import type { WidgetComponentProps } from "../definition"; import classes from "./component.module.scss"; +import { offscreenRowStyle } from "../common/offscreen-rows"; const useLiveFeedEntries = (input: RouterInputs["widget"]["rssFeed"]["getFeeds"]) => { const { data: feedEntries = [] } = clientApi.widget.rssFeed.getFeeds.useQuery(input); @@ -37,18 +38,19 @@ export default function RssFeed({ options, width }: WidgetComponentProps<"rssFee key={feedEntry.id} component={"a"} href={feedEntry.link} + style={offscreenRowStyle(96)} radius={board.itemRadius} target="_blank" w="100%" p="sm" > {feedEntry.enclosure !== undefined && ( - backdrop + backdrop )} {feedEntry.enclosure !== undefined && options.showPosterImage && !isNarrow && ( - {feedEntry.title} + {feedEntry.title} )}