import { HydrationMetricsSnapshot } from '../types';
/**
* Extended metrics with computed values.
*/
export interface UseHydrationMetricsReturn extends HydrationMetricsSnapshot {
/**
* Hydration progress as a percentage (0-100).
*/
readonly hydrationProgress: number;
/**
* Estimated time remaining for full hydration in milliseconds.
* null if not enough data for estimation.
*/
readonly estimatedTimeRemaining: number | null;
/**
* Current hydration rate (boundaries per second).
*/
readonly hydrationRate: number;
/**
* Whether all boundaries have been hydrated.
*/
readonly isFullyHydrated: boolean;
/**
* Whether above-the-fold content has been hydrated.
*/
readonly isAboveFoldHydrated: boolean;
/**
* Interaction replay success rate (0-1).
*/
readonly replaySuccessRate: number;
/**
* History of hydration durations for charting.
*/
readonly durationHistory: readonly number[];
/**
* Manually refresh the metrics.
*/
readonly refresh: () => void;
}
/**
* Options for the useHydrationMetrics hook.
*/
export interface UseHydrationMetricsOptions {
/**
* Polling interval for metrics updates in milliseconds.
* Set to 0 to disable polling.
*
* @default 1000
*/
readonly pollInterval?: number;
/**
* Maximum number of duration entries to keep in history.
*
* @default 50
*/
readonly historySize?: number;
/**
* Whether to enable real-time updates via events.
*
* @default true
*/
readonly realtime?: boolean;
}
/**
* Hook for accessing and monitoring hydration performance metrics.
*
* Provides real-time access to hydration metrics with computed values
* for progress tracking, rate estimation, and performance analysis.
*
* @param options - Hook options
* @returns Extended hydration metrics
*
* @example
* ```tsx
* // Basic metrics display
* function MetricsDisplay() {
* const {
* hydrationProgress,
* averageHydrationDuration,
* isFullyHydrated,
* } = useHydrationMetrics();
*
* return (
*
*
*
{hydrationProgress.toFixed(0)}% hydrated
*
Avg: {averageHydrationDuration.toFixed(0)}ms
* {isFullyHydrated &&
All components interactive!}
*
* );
* }
*
* // Performance monitoring integration
* function PerformanceMonitor() {
* const metrics = useHydrationMetrics({ pollInterval: 500 });
*
* useEffect(() => {
* // Report to analytics when fully hydrated
* if (metrics.isFullyHydrated && metrics.timeToFullHydration) {
* analytics.track('full_hydration', {
* duration: metrics.timeToFullHydration,
* average: metrics.averageHydrationDuration,
* p95: metrics.p95HydrationDuration,
* totalBoundaries: metrics.totalBoundaries,
* });
* }
* }, [metrics.isFullyHydrated, metrics]);
*
* return null;
* }
*
* // Duration history chart
* function DurationChart() {
* const { durationHistory, averageHydrationDuration } = useHydrationMetrics({
* historySize: 100,
* });
*
* return (
*
* );
* }
* ```
*/
export declare function useHydrationMetrics(options?: UseHydrationMetricsOptions): UseHydrationMetricsReturn;
/**
* Hook for watching a specific metric value.
*
* Useful for triggering effects when metrics cross thresholds.
*
* @param selector - Function to select the metric value
* @param options - Hook options
* @returns The selected metric value
*
* @example
* ```tsx
* function ProgressWatcher() {
* const progress = useHydrationMetricValue((m) => m.hydrationProgress);
*
* useEffect(() => {
* if (progress >= 50) {
* console.log('Half hydrated!');
* }
* if (progress >= 100) {
* console.log('Fully hydrated!');
* }
* }, [progress]);
*
* return Progress: {progress.toFixed(0)}%;
* }
* ```
*/
export declare function useHydrationMetricValue(selector: (metrics: UseHydrationMetricsReturn) => T, options?: UseHydrationMetricsOptions): T;
/**
* Hook for getting hydration progress.
*
* @returns Hydration progress percentage (0-100)
*
* @example
* ```tsx
* function ProgressBar() {
* const progress = useHydrationProgress();
* return ;
* }
* ```
*/
export declare function useHydrationProgress(): number;
/**
* Hook for checking if hydration is complete.
*
* @returns true if all boundaries are hydrated
*
* @example
* ```tsx
* function LoadingIndicator() {
* const isComplete = useIsHydrationComplete();
*
* if (isComplete) {
* return null;
* }
*
* return ;
* }
* ```
*/
export declare function useIsHydrationComplete(): boolean;
/**
* Hook for getting time to full hydration.
*
* @returns Time to full hydration in ms, or null if not complete
*
* @example
* ```tsx
* function HydrationTime() {
* const time = useTimeToFullHydration();
*
* if (time === null) {
* return Hydrating...;
* }
*
* return Hydrated in {time.toFixed(0)}ms;
* }
* ```
*/
export declare function useTimeToFullHydration(): number | null;
/**
* Hook for debugging hydration metrics.
*
* Logs metrics to console on each update.
*
* @param label - Label for console output
*
* @example
* ```tsx
* function DebugComponent() {
* useHydrationMetricsDebug('HydrationMetrics');
* return Check console for metrics
;
* }
* ```
*/
export declare function useHydrationMetricsDebug(label?: string): void;