Files
prowler/ui/hooks/use-runtime-config.ts
T
Pablo Fernandez Guerra (PFE) 853610bbbf feat(ui): resolve public SaaS config at container runtime (#11500)
Co-authored-by: Pablo F.G <pablo.fernandez@prowler.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 15:12:18 +02:00

26 lines
804 B
TypeScript

"use client";
import { useSyncExternalStore } from "react";
import { getRuntimeConfigClient } from "@/lib/get-runtime-config.client";
import {
EMPTY_RUNTIME_PUBLIC_CONFIG,
type RuntimePublicConfig,
} from "@/lib/runtime-config.shared";
// The island is browser-only, so SSR and the first hydration render must see
// the empty config to avoid a mismatch; useSyncExternalStore swaps to the
// island value afterwards. Both snapshots must be referentially stable.
const subscribe = () => () => {}; // config is immutable after load — never notifies
const getServerSnapshot = (): RuntimePublicConfig =>
EMPTY_RUNTIME_PUBLIC_CONFIG;
export function useRuntimeConfig(): RuntimePublicConfig {
return useSyncExternalStore(
subscribe,
getRuntimeConfigClient,
getServerSnapshot,
);
}