{"version":3,"file":"HydrationBoundary.mjs","sources":["../../../src/lib/hydration/HydrationBoundary.tsx"],"sourcesContent":["/**\n * @file Hydration Boundary Component\n * @description Wraps components for selective, prioritized hydration.\n *\n * HydrationBoundary creates a boundary around components that should be\n * hydrated on demand rather than immediately. It provides:\n *\n * - Configurable hydration priority and triggers\n * - Placeholder rendering before hydration\n * - Error handling with fallback rendering\n * - Integration with the hydration scheduler\n * - Support for interaction capture and replay\n *\n * @module hydration/HydrationBoundary\n *\n * @example\n * ```tsx\n * // Basic usage - hydrate when visible\n * <HydrationBoundary priority=\"normal\" trigger=\"visible\">\n *   <ExpensiveComponent />\n * </HydrationBoundary>\n *\n * // Critical above-the-fold content\n * <HydrationBoundary\n *   priority=\"critical\"\n *   trigger=\"immediate\"\n *   aboveTheFold\n * >\n *   <HeroSection />\n * </HydrationBoundary>\n *\n * // Interaction-triggered with placeholder\n * <HydrationBoundary\n *   priority=\"high\"\n *   trigger=\"interaction\"\n *   placeholder={<SkeletonButton />}\n * >\n *   <InteractiveButton />\n * </HydrationBoundary>\n * ```\n */\n\nimport React, {\n  useRef,\n  useState,\n  useEffect,\n  useCallback,\n  useMemo,\n  useId,\n  type ReactNode,\n  type ComponentType,\n  type CSSProperties,\n  lazy,\n  Suspense,\n} from 'react';\n\nimport { useOptionalHydrationContext } from './HydrationProvider';\n\nimport type {\n  HydrationBoundaryProps,\n  HydrationBoundaryId,\n  HydrationTask,\n  WithHydrationBoundaryOptions,\n} from './types';\n\nimport { createBoundaryId } from './types';\nimport { isDev } from '@/lib/core/config/env-helper';\n\n// ============================================================================\n// Internal Types\n// ============================================================================\n\n/**\n * Captured interaction event for replay after hydration\n */\ninterface CapturedInteraction {\n  type: string;\n  target: EventTarget | null;\n  timestamp: number;\n  clientX?: number;\n  clientY?: number;\n}\n\ninterface HydrationBoundaryState {\n  hydrationState:\n    | 'idle'\n    | 'loading'\n    | 'complete'\n    | 'error'\n    | 'pending'\n    | 'hydrated'\n    | 'hydrating'\n    | 'skipped';\n  error: Error | null;\n  isClient: boolean;\n}\n\n// ============================================================================\n// Utility Functions\n// ============================================================================\n\n/**\n * Generates a stable boundary ID.\n */\nfunction generateBoundaryId(providedId: string | undefined, reactId: string): HydrationBoundaryId {\n  const id = providedId ?? `hydration-boundary-${reactId.replace(/:/g, '-')}`;\n  return createBoundaryId(id);\n}\n\n/**\n * Default placeholder for loading state.\n */\nfunction DefaultPlaceholder(): React.JSX.Element {\n  return (\n    <div\n      className=\"hydration-placeholder\"\n      style={{\n        minHeight: '1em',\n        background: 'transparent',\n      }}\n      aria-hidden=\"true\"\n    />\n  );\n}\n\n/**\n * Default error fallback.\n */\nfunction DefaultErrorFallback({ error }: { error: Error }): React.JSX.Element {\n  return (\n    <div\n      className=\"hydration-error\"\n      role=\"alert\"\n      style={{\n        padding: '1rem',\n        backgroundColor: 'rgba(239, 68, 68, 0.1)',\n        border: '1px solid rgba(239, 68, 68, 0.3)',\n        borderRadius: '4px',\n        color: 'inherit',\n      }}\n    >\n      <strong>Component Error</strong>\n      <p style={{ margin: '0.5rem 0 0', fontSize: '0.875em', opacity: 0.8 }}>{error.message}</p>\n    </div>\n  );\n}\n\n// ============================================================================\n// HydrationBoundary Component\n// ============================================================================\n\n/**\n * Wraps components for selective, prioritized hydration.\n *\n * This component integrates with the HydrationScheduler to provide\n * controlled hydration timing based on priority, visibility, and\n * user interactions.\n *\n * @param props - Boundary props\n * @returns The boundary wrapper with children or placeholder\n */\nexport function HydrationBoundary({\n  id: providedId,\n  children,\n  priority = 'normal',\n  trigger = 'visible',\n  placeholder,\n  errorFallback,\n  onHydrationStart,\n  onHydrationComplete,\n  onHydrationError,\n  ssrOnly = false,\n  mediaQuery,\n  timeout,\n  estimatedCost,\n  aboveTheFold = false,\n  className,\n  style,\n}: HydrationBoundaryProps): React.JSX.Element {\n  // ==========================================================================\n  // Refs and IDs\n  // ==========================================================================\n\n  const reactId = useId();\n  const boundaryId = useMemo(() => generateBoundaryId(providedId, reactId), [providedId, reactId]);\n\n  const containerRef = useRef<HTMLDivElement>(null);\n  const hydrationCallbackRef = useRef<(() => Promise<void>) | null>(null);\n  const capturedInteractionsRef = useRef<CapturedInteraction[]>([]);\n\n  // ==========================================================================\n  // Context\n  // ==========================================================================\n\n  const hydrationContext = useOptionalHydrationContext();\n\n  // ==========================================================================\n  // State\n  // ==========================================================================\n\n  const [state, setState] = useState<HydrationBoundaryState>({\n    hydrationState: 'pending',\n    error: null,\n    isClient: false,\n  });\n\n  // ==========================================================================\n  // Client Detection\n  // ==========================================================================\n\n  useEffect(() => {\n    queueMicrotask(() => {\n      setState((prev) => ({ ...prev, isClient: true }));\n    });\n  }, []);\n\n  // ==========================================================================\n  // Hydration Callback\n  // ==========================================================================\n\n  /**\n   * Capture interaction events during pre-hydration state.\n   * INP Optimization: Instead of blocking all interactions with pointerEvents: 'none',\n   * we capture them and replay after hydration completes.\n   */\n  const captureInteraction = useCallback(\n    (event: React.MouseEvent | React.TouchEvent | React.KeyboardEvent) => {\n      // Only capture if not yet hydrated\n      if (state.hydrationState !== 'pending' && state.hydrationState !== 'hydrating') {\n        return;\n      }\n\n      const captured: CapturedInteraction = {\n        type: event.type,\n        target: event.target,\n        timestamp: Date.now(),\n      };\n\n      // Capture position for mouse/touch events\n      if ('clientX' in event) {\n        captured.clientX = event.clientX;\n        captured.clientY = event.clientY;\n      }\n\n      capturedInteractionsRef.current.push(captured);\n\n      // Prevent the event from propagating during pre-hydration\n      event.preventDefault();\n      event.stopPropagation();\n    },\n    [state.hydrationState]\n  );\n\n  /**\n   * Replay captured interactions after hydration completes.\n   */\n  const replayCapturedInteractions = useCallback(() => {\n    const interactions = capturedInteractionsRef.current;\n    if (interactions.length === 0) return;\n\n    // Replay interactions with a small delay to ensure DOM is ready\n    requestAnimationFrame(() => {\n      for (const interaction of interactions) {\n        if (interaction.target && interaction.target instanceof Element) {\n          try {\n            // For click events, dispatch a new click event\n            if (interaction.type === 'click' || interaction.type === 'mousedown') {\n              const clickEvent = new MouseEvent('click', {\n                bubbles: true,\n                cancelable: true,\n                clientX: interaction.clientX,\n                clientY: interaction.clientY,\n              });\n              interaction.target.dispatchEvent(clickEvent);\n            }\n          } catch {\n            // Silently fail if replay fails\n          }\n        }\n      }\n\n      // Clear captured interactions after replay\n      capturedInteractionsRef.current = [];\n    });\n  }, []);\n\n  /**\n   * The actual hydration function that transitions state.\n   */\n  const performHydration = useCallback(async (): Promise<void> => {\n    // Call start callback\n    onHydrationStart?.();\n\n    // Simply transition to hydrated state\n    // The children are already rendered, this just marks them as interactive\n    return new Promise<void>((resolve) => {\n      // Use requestAnimationFrame to ensure we don't block the main thread\n      requestAnimationFrame(() => {\n        setState((prev) => ({\n          ...prev,\n          hydrationState: 'hydrated',\n        }));\n\n        // Replay any captured interactions after hydration\n        replayCapturedInteractions();\n\n        resolve();\n      });\n    });\n  }, [onHydrationStart, replayCapturedInteractions]);\n\n  // Store in ref for scheduler (in effect to avoid ref access during render)\n  useEffect(() => {\n    hydrationCallbackRef.current = performHydration;\n  }, [performHydration]);\n\n  // ==========================================================================\n  // Scheduler Registration\n  // ==========================================================================\n\n  useEffect(() => {\n    // Skip if SSR-only\n    if (ssrOnly) {\n      queueMicrotask(() => {\n        setState((prev) => ({ ...prev, hydrationState: 'skipped' }));\n      });\n      return;\n    }\n\n    // Skip if no context or not on client\n    if (hydrationContext == null || !state.isClient) {\n      // Without context, hydrate immediately\n      if (state.isClient) {\n        queueMicrotask(() => {\n          setState((prev) => ({ ...prev, hydrationState: 'hydrated' }));\n        });\n      }\n      return;\n    }\n\n    // Create task\n    const task: HydrationTask = {\n      id: boundaryId,\n      priority,\n      trigger,\n      hydrate: async () => {\n        const startTime = performance.now();\n\n        try {\n          setState((prev) => ({ ...prev, hydrationState: 'hydrating' }));\n          await hydrationCallbackRef.current?.();\n\n          const duration = performance.now() - startTime;\n          onHydrationComplete?.(duration);\n        } catch (error) {\n          const err = error instanceof Error ? error : new Error(String(error));\n          setState((prev) => ({\n            ...prev,\n            hydrationState: 'error',\n            error: err,\n          }));\n          onHydrationError?.(err);\n          throw err;\n        }\n      },\n      onHydrated: () => {\n        // Additional cleanup if needed\n      },\n      onError: (error) => {\n        console.error(`[HydrationBoundary] Error hydrating ${boundaryId}:`, error);\n      },\n      enqueuedAt: Date.now(),\n      element: containerRef.current,\n      estimatedCost,\n      timeout,\n      cancellable: true,\n      metadata: {\n        componentName: providedId,\n        aboveTheFold,\n        routePath: mediaQuery,\n      },\n    };\n\n    // Register with scheduler\n    hydrationContext.registerBoundary(task);\n\n    // Cleanup on unmount\n    return () => {\n      hydrationContext.unregisterBoundary(boundaryId);\n    };\n  }, [\n    boundaryId,\n    priority,\n    trigger,\n    ssrOnly,\n    hydrationContext,\n    state.isClient,\n    estimatedCost,\n    timeout,\n    aboveTheFold,\n    providedId,\n    mediaQuery,\n    onHydrationComplete,\n    onHydrationError,\n  ]);\n\n  // ==========================================================================\n  // Render Logic\n  // ==========================================================================\n\n  /**\n   * Determines what to render based on current state.\n   */\n  const renderContent = (): ReactNode => {\n    // SSR-only: render children without interactivity\n    if (ssrOnly) {\n      return children;\n    }\n\n    // Error state\n    if (state.hydrationState === 'error' && state.error != null) {\n      if (typeof errorFallback === 'function') {\n        return errorFallback(state.error);\n      }\n      if (errorFallback != null) {\n        return errorFallback;\n      }\n      return <DefaultErrorFallback error={state.error} />;\n    }\n\n    // Not yet on client - render placeholder for SSR\n    if (!state.isClient) {\n      return placeholder ?? <DefaultPlaceholder />;\n    }\n\n    // Pending/Hydrating - render children with interaction capture\n    // INP Optimization: Instead of blocking interactions with pointerEvents: 'none',\n    // we capture them and replay after hydration for better perceived responsiveness\n    if (state.hydrationState === 'pending' || state.hydrationState === 'hydrating') {\n      return (\n        <>\n          {/* Render actual children with interaction capture for INP optimization */}\n          <div\n            className=\"hydration-content\"\n            aria-hidden=\"false\"\n            onClickCapture={captureInteraction}\n            onMouseDownCapture={captureInteraction}\n            onTouchStartCapture={captureInteraction}\n            onKeyDownCapture={captureInteraction}\n          >\n            {children}\n          </div>\n          {/* Optional loading indicator for hydrating state */}\n          {state.hydrationState === 'hydrating' && (\n            <div\n              className=\"hydration-loading-indicator\"\n              style={{\n                position: 'absolute',\n                inset: 0,\n                display: 'flex',\n                alignItems: 'center',\n                justifyContent: 'center',\n                background: 'rgba(255, 255, 255, 0.5)',\n                backdropFilter: 'blur(1px)',\n                pointerEvents: 'none',\n              }}\n              aria-label=\"Loading...\"\n            />\n          )}\n        </>\n      );\n    }\n\n    // Hydrated - render fully interactive children\n    return children;\n  };\n\n  // ==========================================================================\n  // Container Styles\n  // ==========================================================================\n\n  const containerStyles = useMemo<CSSProperties>(() => {\n    const baseStyles: CSSProperties = {\n      position: 'relative',\n      ...style,\n    };\n\n    // Add visual indicators in development\n    if (isDev()) {\n      if (state.hydrationState === 'pending') {\n        baseStyles.outline = '1px dashed rgba(59, 130, 246, 0.5)';\n      } else if (state.hydrationState === 'hydrating') {\n        baseStyles.outline = '1px solid rgba(59, 130, 246, 0.8)';\n      }\n    }\n\n    return baseStyles;\n  }, [style, state.hydrationState]);\n\n  // ==========================================================================\n  // Render\n  // ==========================================================================\n\n  return (\n    <div\n      ref={containerRef}\n      id={boundaryId}\n      className={`hydration-boundary hydration-${state.hydrationState} ${className ?? ''}`}\n      style={containerStyles}\n      data-hydration-state={state.hydrationState}\n      data-hydration-priority={priority}\n      data-hydration-trigger={trigger}\n      data-hydration-boundary-id={boundaryId}\n    >\n      {renderContent()}\n    </div>\n  );\n}\n\n// ============================================================================\n// Higher-Order Component\n// ============================================================================\n\n/* eslint-disable react-refresh/only-export-components */\n/**\n * HOC to wrap a component with a HydrationBoundary.\n *\n * @param Component - The component to wrap\n * @param options - Boundary options\n * @returns Wrapped component with hydration boundary\n *\n * @example\n * ```tsx\n * const HydratedChart = withHydrationBoundary(Chart, {\n *   defaultPriority: 'low',\n *   defaultTrigger: 'visible',\n *   placeholder: <ChartSkeleton />,\n * });\n *\n * // Use like normal component\n * <HydratedChart data={chartData} />\n *\n * // Override boundary props as needed\n * <HydratedChart data={chartData} priority=\"high\" />\n * ```\n */\nexport function withHydrationBoundary<P extends object>(\n  Component: ComponentType<P>,\n  options: WithHydrationBoundaryOptions<P> = {}\n): ComponentType<P & Partial<HydrationBoundaryProps>> {\n  const {\n    displayName,\n    defaultPriority = 'normal',\n    defaultTrigger = 'visible',\n    placeholder: optionPlaceholder,\n    aboveTheFold: optionAboveTheFold = false,\n    estimatedCost: optionEstimatedCost,\n  } = options;\n\n  function WrappedComponent(props: P & Partial<HydrationBoundaryProps>): React.JSX.Element {\n    const {\n      priority = defaultPriority,\n      trigger = defaultTrigger,\n      placeholder = typeof optionPlaceholder === 'function'\n        ? optionPlaceholder(props as P)\n        : optionPlaceholder,\n      aboveTheFold = optionAboveTheFold,\n      estimatedCost = optionEstimatedCost,\n      id,\n      errorFallback,\n      onHydrationStart,\n      onHydrationComplete,\n      onHydrationError,\n      ssrOnly,\n      visibilityConfig,\n      mediaQuery,\n      timeout,\n      className,\n      style,\n      ...componentProps\n    } = props;\n\n    return (\n      <HydrationBoundary\n        id={id}\n        priority={priority}\n        trigger={trigger}\n        placeholder={placeholder}\n        errorFallback={errorFallback}\n        onHydrationStart={onHydrationStart}\n        onHydrationComplete={onHydrationComplete}\n        onHydrationError={onHydrationError}\n        ssrOnly={ssrOnly}\n        visibilityConfig={visibilityConfig}\n        mediaQuery={mediaQuery}\n        timeout={timeout}\n        estimatedCost={estimatedCost}\n        aboveTheFold={aboveTheFold}\n        className={className}\n        style={style}\n      >\n        <Component {...(componentProps as P)} />\n      </HydrationBoundary>\n    );\n  }\n\n  WrappedComponent.displayName =\n    displayName ??\n    `withHydrationBoundary(${Component.displayName ?? Component.name ?? 'Component'})`;\n\n  return WrappedComponent;\n}\n\n// ============================================================================\n// Lazy Hydration Component\n// ============================================================================\n\n/**\n * Props for LazyHydration component.\n */\ninterface LazyHydrationProps<P extends object> {\n  /** Factory function that returns a promise resolving to the component */\n  factory: () => Promise<{ default: ComponentType<P> }>;\n  /** Props to pass to the lazy-loaded component */\n  componentProps: P;\n  /** Hydration boundary props */\n  boundaryProps?: Partial<HydrationBoundaryProps>;\n}\n\n/**\n * Combines React.lazy with HydrationBoundary for maximum efficiency.\n *\n * This component provides both code-splitting (via React.lazy) and\n * selective hydration (via HydrationBoundary).\n *\n * @example\n * ```tsx\n * <LazyHydration\n *   factory={() => import('./HeavyChart')}\n *   componentProps={{ data: chartData }}\n *   boundaryProps={{\n *     priority: 'low',\n *     trigger: 'visible',\n *     placeholder: <ChartSkeleton />,\n *   }}\n * />\n * ```\n */\nexport function LazyHydration<P extends object>({\n  factory,\n  componentProps,\n  boundaryProps = {},\n}: LazyHydrationProps<P>): React.JSX.Element {\n  // Create lazy component once with proper typing\n  const LazyComponent = useMemo(() => lazy(factory), [factory]);\n\n  const { placeholder = <DefaultPlaceholder />, ...restBoundaryProps } = boundaryProps;\n\n  return (\n    <HydrationBoundary {...restBoundaryProps} placeholder={placeholder}>\n      <Suspense fallback={placeholder}>\n        <LazyComponent {...componentProps} />\n      </Suspense>\n    </HydrationBoundary>\n  );\n}\n\n// ============================================================================\n// Exports\n// ============================================================================\n\nexport type { HydrationBoundaryProps, WithHydrationBoundaryOptions, LazyHydrationProps };\n"],"names":["generateBoundaryId","providedId","reactId","id","createBoundaryId","DefaultPlaceholder","jsx","DefaultErrorFallback","error","jsxs","HydrationBoundary","children","priority","trigger","placeholder","errorFallback","onHydrationStart","onHydrationComplete","onHydrationError","ssrOnly","mediaQuery","timeout","estimatedCost","aboveTheFold","className","style","useId","boundaryId","useMemo","containerRef","useRef","hydrationCallbackRef","capturedInteractionsRef","hydrationContext","useOptionalHydrationContext","state","setState","useState","useEffect","prev","captureInteraction","useCallback","event","captured","replayCapturedInteractions","interactions","interaction","clickEvent","performHydration","resolve","task","startTime","duration","err","renderContent","Fragment","containerStyles","baseStyles","isDev","withHydrationBoundary","Component","options","displayName","defaultPriority","defaultTrigger","optionPlaceholder","optionAboveTheFold","optionEstimatedCost","WrappedComponent","props","visibilityConfig","componentProps","LazyHydration","factory","boundaryProps","LazyComponent","lazy","restBoundaryProps","Suspense"],"mappings":";;;;;AAwGA,SAASA,EAAmBC,GAAgCC,GAAsC;AAChG,QAAMC,IAAKF,KAAc,sBAAsBC,EAAQ,QAAQ,MAAM,GAAG,CAAC;AACzE,SAAOE,EAAiBD,CAAE;AAC5B;AAKA,SAASE,IAAwC;AAC/C,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACV,OAAO;AAAA,QACL,WAAW;AAAA,QACX,YAAY;AAAA,MAAA;AAAA,MAEd,eAAY;AAAA,IAAA;AAAA,EAAA;AAGlB;AAKA,SAASC,EAAqB,EAAE,OAAAC,KAA8C;AAC5E,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAU;AAAA,MACV,MAAK;AAAA,MACL,OAAO;AAAA,QACL,SAAS;AAAA,QACT,iBAAiB;AAAA,QACjB,QAAQ;AAAA,QACR,cAAc;AAAA,QACd,OAAO;AAAA,MAAA;AAAA,MAGT,UAAA;AAAA,QAAA,gBAAAH,EAAC,YAAO,UAAA,kBAAA,CAAe;AAAA,QACvB,gBAAAA,EAAC,KAAA,EAAE,OAAO,EAAE,QAAQ,cAAc,UAAU,WAAW,SAAS,IAAA,GAAQ,UAAAE,EAAM,QAAA,CAAQ;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAG5F;AAgBO,SAASE,EAAkB;AAAA,EAChC,IAAIT;AAAA,EACJ,UAAAU;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC,IAAU;AAAA,EACV,aAAAC;AAAA,EACA,eAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,YAAAC;AAAA,EACA,SAAAC;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,WAAAC;AAAA,EACA,OAAAC;AACF,GAA8C;AAK5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