"use client"; import { useEffect, useState } from "react"; import { usePathname } from "next/navigation"; import { TanStackDevtools } from "@tanstack/react-devtools"; import type { TanStackDevtoolsReactPlugin } from "@tanstack/react-devtools"; import type { QueryClient } from "@tanstack/react-query"; import { useQueryClient } from "@tanstack/react-query"; import { ReactQueryDevtoolsPanel } from "@tanstack/react-query-devtools"; const valueStyle = { fontFamily: "monospace", overflowWrap: "anywhere" } as const; const metricStyle = { background: "color-mix(in srgb, currentColor 4%, transparent)", border: "1px solid color-mix(in srgb, currentColor 18%, transparent)", borderRadius: 8, padding: 12, } as const; const readDiagnostics = (queryClient: QueryClient) => { const queries = queryClient.getQueryCache().getAll(); const mutations = queryClient.getMutationCache().getAll(); const board = document.querySelector("[data-homarr-dev-benchmark-board]"); const widgetItems = board?.querySelectorAll('[data-type="item"]').length ?? 0; const readyWidgets = board?.querySelectorAll("[data-homarr-widget-ready]").length ?? 0; const resources = performance.getEntriesByType("resource") as PerformanceResourceTiming[]; return { active: queries.filter((query) => query.getObserversCount() > 0).length, errors: queries.filter((query) => query.state.status === "error").length, fetching: queries.filter((query) => query.state.fetchStatus === "fetching").length, pendingMutations: mutations.filter((mutation) => mutation.state.status === "pending").length, stale: queries.filter((query) => query.isStale()).length, total: queries.length, readyWidgets, widgetItems, scriptKiB: Math.round( resources .filter((resource) => resource.initiatorType === "script") .reduce((total, resource) => total + resource.decodedBodySize, 0) / 1024, ), }; }; const Metric = ({ label, value }: { label: string; value: number | string }) => (
Live state for {pathname}