perf(widgets): stop building collapsed Accordion panels
From reading PR #6582, which adds keepMounted={false} to the two coolify accordions. The widget sweep had checked Tabs and never checked Accordion, so it missed this on all five sites - an honest gap that PR closed for two of them. Accordion behaves exactly like Tabs, verified in the installed version rather than assumed: with three marker children per panel, the default renders 3 of 3 children of the *collapsed* panel and keepMounted={false} renders 0. It matters more here than in Tabs, because collapsed is an accordion section's normal state rather than the exception: coolify instance-card three remote-data lists: servers, applications, services - all built while collapsed coolify single-instance-layout same three lists health-monitoring cluster per-node resource tables (beyond #6582) firewall interface rows (beyond #6582) Left mounted: the multiReleasesRepositories input, which holds selection state and is edit-modal only rather than on the board render path. In every fixed case the open/closed state lives in the parent, so unmounting a collapsed panel discards nothing. The spec is renamed tabs-keep-mounted -> keep-mounted since it now pins both components, and three verdicts in the audit table are corrected: coolify was recorded "clean (bounded)" and firewall triaged on other grounds, while both were carrying this cost.
This commit is contained in:
6 files changed
+122
-10
No files matched your search
+69
-1
@@ -1,4 +1,4 @@
|
||||
import { MantineProvider, Tabs } from "@mantine/core";
|
||||
import { Accordion, MantineProvider, Tabs } from "@mantine/core";
|
||||
import { act, createElement } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { afterEach, beforeAll, describe, expect, it } from "vitest";
|
||||
@@ -100,3 +100,71 @@ describe("Mantine Tabs keepMounted", () => {
|
||||
expect(counts.offscreen).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* `Accordion` has the same behaviour and the same prop, which the widget sweep originally missed - it
|
||||
* checked `Tabs` and not `Accordion`. Collapsed panels matter more here, because a collapsed accordion
|
||||
* section is the *normal* state rather than the exception: coolify renders three remote-data resource
|
||||
* lists this way, cluster-health its node tables, firewall its interface rows.
|
||||
*/
|
||||
describe("Mantine Accordion keepMounted", () => {
|
||||
let container: HTMLDivElement;
|
||||
let root: Root;
|
||||
|
||||
afterEach(() => {
|
||||
root?.unmount();
|
||||
container?.remove();
|
||||
});
|
||||
|
||||
const renderAccordion = async (keepMounted: boolean | undefined) => {
|
||||
container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
root = createRoot(container);
|
||||
|
||||
const item = (value: string, marker: string) =>
|
||||
createElement(Accordion.Item, { value, key: value }, [
|
||||
createElement(Accordion.Control, { key: "control" }, value),
|
||||
createElement(
|
||||
Accordion.Panel,
|
||||
{ key: "panel" },
|
||||
Array.from({ length: 3 }, (_unused, index) =>
|
||||
createElement("span", { className: marker, key: index }, `${marker}-${index}`),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
await act(async () => {
|
||||
root.render(
|
||||
createElement(
|
||||
MantineProvider,
|
||||
null,
|
||||
createElement(
|
||||
Accordion,
|
||||
{ defaultValue: "open", ...(keepMounted === undefined ? {} : { keepMounted }) },
|
||||
item("open", "shown"),
|
||||
item("collapsed", "offscreen"),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
return {
|
||||
shown: container.querySelectorAll(".shown").length,
|
||||
offscreen: container.querySelectorAll(".offscreen").length,
|
||||
};
|
||||
};
|
||||
|
||||
it("renders collapsed panel children by default, which is the cost being avoided", async () => {
|
||||
const counts = await renderAccordion(undefined);
|
||||
|
||||
expect(counts.shown).toBe(3);
|
||||
expect(counts.offscreen).toBe(3);
|
||||
});
|
||||
|
||||
it("does not render collapsed panel children when keepMounted is false", async () => {
|
||||
const counts = await renderAccordion(false);
|
||||
|
||||
expect(counts.shown).toBe(3);
|
||||
expect(counts.offscreen).toBe(0);
|
||||
});
|
||||
});
|
||||
@@ -90,7 +90,16 @@ export function InstanceCard({ instance, options, isTiny, widgetKey }: InstanceC
|
||||
</Group>
|
||||
</Group>
|
||||
|
||||
<Accordion variant="filled" chevronPosition="right" multiple value={openSections} onChange={setOpenSections}>
|
||||
{/* Collapsed panels are rendered by default, so all three resource lists were built even when
|
||||
none is open. The open sections are parent state, so nothing is lost by unmounting. */}
|
||||
<Accordion
|
||||
variant="filled"
|
||||
chevronPosition="right"
|
||||
multiple
|
||||
keepMounted={false}
|
||||
value={openSections}
|
||||
onChange={setOpenSections}
|
||||
>
|
||||
{options.showServers && (
|
||||
<ServersSection
|
||||
servers={instance.instanceInfo.servers}
|
||||
|
||||
@@ -56,7 +56,14 @@ export function SingleInstanceLayout({ instance, options, isTiny, widgetKey }: S
|
||||
</Anchor>
|
||||
</Group>
|
||||
|
||||
<Accordion variant="contained" chevronPosition="right" multiple value={openSections} onChange={setOpenSections}>
|
||||
<Accordion
|
||||
variant="contained"
|
||||
chevronPosition="right"
|
||||
multiple
|
||||
keepMounted={false}
|
||||
value={openSections}
|
||||
onChange={setOpenSections}
|
||||
>
|
||||
{options.showServers && (
|
||||
<ServersSection
|
||||
servers={instance.instanceInfo.servers}
|
||||
|
||||
@@ -120,7 +120,7 @@ export default function FirewallWidget({ integrationIds, width, itemId }: Widget
|
||||
{firewallsInterfacesData
|
||||
.filter(({ integration }) => integration.id === (selectedFirewall || initialSelectedFirewall))
|
||||
.map(({ summary }) => (
|
||||
<Accordion key="interfaces" value={accordionValue} onChange={setAccordionValue}>
|
||||
<Accordion key="interfaces" keepMounted={false} value={accordionValue} onChange={setAccordionValue}>
|
||||
<Accordion.Item value="interfaces">
|
||||
<Accordion.Control icon={isTiny ? null : <IconTopologyBus size={16} />}>
|
||||
<Text size={isTiny ? "8px" : "xs"}> {t("widget.firewall.widget.interfaces.title")} </Text>
|
||||
|
||||
@@ -81,7 +81,7 @@ export const ClusterHealthMonitoring = ({
|
||||
isTiny={isTiny}
|
||||
/>
|
||||
{options.visibleClusterSections.length >= 1 && (
|
||||
<Accordion variant="contained" chevronPosition="right" multiple defaultValue={defaultValue}>
|
||||
<Accordion variant="contained" chevronPosition="right" multiple keepMounted={false} defaultValue={defaultValue}>
|
||||
{options.visibleClusterSections.includes("node") && (
|
||||
<ResourceAccordionItem
|
||||
value="node"
|
||||
|
||||
Reference in new issue
Block a user