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.
This commit is contained in:
Thomas Camlong committed 2026-08-11 09:37:48 +02:00
1 parent 8f94ea47e3
commit 040f105946
4 files changed
+40 -4

No files matched your search

@@ -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) => {
>
<Stack>
{events.map((event, eventIndex) => (
<Group key={`event-${eventIndex}`} align={"stretch"} wrap="nowrap">
<Group key={`event-${eventIndex}`} align={"stretch"} wrap="nowrap" style={offscreenRowStyle(110)}>
{event.image !== null && (
<Box pos="relative">
<Image
src={event.image.src}
loading="lazy"
w={70}
mah={150}
style={{
@@ -0,0 +1,31 @@
import type { CSSProperties } from "react";
/**
* Style for a row in a widget that renders a list it does not bound.
*
* Widgets like these map over everything an integration returns and put it all in the DOM, while the
* tile shows a handful of rows. Measured on a real board: the media-releases widget rendered 80 cards
* into a 539 px tile whose content was 7,206 px tall — 73 of them entirely off-screen, each still
* costing layout, paint, raster, and an image fetch and decode. Decoded bitmaps are far larger in
* memory than the files they come from, which is what makes this expensive rather than merely untidy.
*
* Applying it there measured, over three repeats per side:
* image requests 135 -> 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`,
});
@@ -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) }}
>
<Flex gap="sm" align="flex-start" w="100%">
{!options.hideLogos && notification.source?.iconUrl && (
+4 -2
View File
@@ -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 && (
<Image className={classes.backgroundImage} src={feedEntry.enclosure} alt="backdrop" />
<Image className={classes.backgroundImage} src={feedEntry.enclosure} alt="backdrop" loading="lazy" />
)}
<Group wrap="nowrap">
{feedEntry.enclosure !== undefined && options.showPosterImage && !isNarrow && (
<Image src={feedEntry.enclosure} alt={feedEntry.title} w={140} h={140} radius="sm" />
<Image src={feedEntry.enclosure} alt={feedEntry.title} w={140} h={140} radius="sm" loading="lazy" />
)}
<Flex gap="sm" direction="column" w="100%">