Skip to main content

Version Components

The Version module displays Git-based data repository version information. It shows commit hashes, authors, timestamps, and sync status, primarily in the site footer. The display is gated so that error states are only visible to developer/admin users.

Architecture Overview

Source Files

FileDescription
components/version/version-display.tsxMulti-variant version display component
components/version/version-tooltip.tsxHover tooltip wrapper showing detailed version
hooks/use-version-info.tsReact Query hook for fetching version data

Components

VersionDisplay

A memoised component that renders version information in one of three visual variants.

import { VersionDisplay } from "@/components/version/version-display";

// Inline (footer)
<VersionDisplay variant="inline" />

// Badge (header)
<VersionDisplay variant="badge" />

// Detailed (tooltip content, admin panels)
<VersionDisplay variant="detailed" showDetails={true} />

Props:

PropTypeDefaultDescription
classNamestring""Additional CSS classes
variant"inline" | "badge" | "detailed""inline"Visual style
showDetailsbooleanfalseShow extended info (detailed variant only)
refreshIntervalnumber300000Polling interval in ms (5 min default)

Variant comparison:

VariantContent shownUse case
inlineCommit hash + relative time + status dotFooter, compact spaces
badgePill with commit, relative time, pulse dotHeader bars, badges
detailedCard with commit, author, message, dates, repoTooltips, admin panels

Error handling:

  • For regular users: the component renders nothing on error.
  • For dev/admin users: shows a "Version unavailable" message with an info icon.

VersionTooltip

A hover-activated tooltip wrapper that displays the detailed version card on mouse enter.

import { VersionTooltip } from "@/components/version/version-tooltip";

<VersionTooltip>
<span>v1.2.3</span>
</VersionTooltip>

Props:

PropTypeDefaultDescription
childrenReactNode--Trigger element
classNamestring""Additional CSS classes
disabledbooleanfalseDisable tooltip entirely
delaynumber300Show delay in milliseconds

Key behaviours:

  • Configurable show delay to prevent accidental triggers.
  • Tooltip stays visible when the cursor moves onto it (prevents flicker).
  • Keyboard accessible: Escape key closes the tooltip.
  • Renders children unchanged when disabled or when version data is unavailable.
  • Cleans up all timeouts on unmount to prevent memory leaks.

Hook: useVersionInfo

A React Query-based hook that fetches and caches version data from the /api/version endpoint.

import { useVersionInfo } from "@/hooks/use-version-info";

const { versionInfo, isLoading, error, refetch } = useVersionInfo({
refreshInterval: 5 * 60 * 1000,
retryOnError: true,
});

Options:

OptionTypeDefaultDescription
refreshIntervalnumber300000Auto-refresh interval (0 to disable)
retryOnErrorbooleantrueEnable retry on failure
enabledbooleantrueEnable/disable the query

Return value:

FieldTypeDescription
versionInfoVersionInfo | nullVersion data object
isLoadingbooleanInitial loading state
isErrorbooleanError state flag
errorUseVersionInfoError | nullError details
refetch() => PromiseManual refetch trigger
isStalebooleanWhether cached data is stale
dataUpdatedAtnumberTimestamp of last successful fetch
invalidateVersionInfo() => PromiseClear the cache

Cache configuration:

  • Stale time: 5 minutes.
  • Garbage collection time: 30 minutes.
  • Does not refetch on window focus (reduces unnecessary API calls).
  • Exponential backoff retry (1s, 2s, 4s, ... up to 30s).
  • Does not retry on 4xx client errors.

useVersionInfoUtils

A companion utility hook for managing the version cache from other parts of the application.

import { useVersionInfoUtils } from "@/hooks/use-version-info";

const { prefetchVersionInfo, invalidateVersionInfo, getVersionInfoFromCache } =
useVersionInfoUtils();

VersionInfo Data Shape

The API returns an object with these fields:

FieldTypeDescription
commitstringShort commit hash
datestringCommit date (ISO 8601)
authorstringCommit author name
messagestringCommit message (first line used in display)
repositorystringRepository URL
lastSyncstringLast sync timestamp

Date Formatting

VersionDisplay uses memoised date formatters:

FunctionOutput example
formatDate"Jan 15, 2025, 02:30 PM"
getRelativeTime"Just now", "3h ago", "2d ago", "Jan 15"
getRepositoryName"ever-works/awesome-data" (extracted from GitHub URL)

Integration Notes

  • VersionDisplay is typically placed in the site footer, controlled by footerSettings.versionEnabled.
  • The component requires the QueryClientProvider ancestor for React Query.
  • Dev/admin detection uses the useIsDevOrAdmin hook (checks session role).
  • The tooltip uses animate-in CSS classes for smooth entrance animations.
  • All version components are client components ('use client' directive).