/** * Mandu Hydration Runtime ๐ŸŒŠ * v0.8.0: Dynamic Import ๊ธฐ๋ฐ˜ ์•„ํ‚คํ…์ฒ˜ * * ์ด ํŒŒ์ผ์€ ํƒ€์ž… ์ •์˜์™€ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํ•จ์ˆ˜๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. * ์‹ค์ œ Hydration Runtime์€ client/runtime-entry.ts์—์„œ ๋ฒˆ๋“ค๋ง๋ฉ๋‹ˆ๋‹ค. */ import { getHydratedRoots, getServerData as getGlobalServerData } from "./window-state"; /** * Hydration ์ƒํƒœ ์ถ”์  */ export interface HydrationState { total: number; hydrated: number; failed: number; recoverableErrors: number; pending: Set; } /** * Hydration ์šฐ์„ ์ˆœ์œ„ */ export type HydrationPriority = "immediate" | "visible" | "idle" | "interaction"; /** * ์„œ๋ฒ„ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ */ export function getServerData(islandId: string): T | undefined { if (typeof window === "undefined") return undefined; return getGlobalServerData(islandId); } /** * Hydration ์ƒํƒœ ์กฐํšŒ (DOM ๊ธฐ๋ฐ˜) */ export function getHydrationState(): Readonly { if (typeof document === "undefined") { return { total: 0, hydrated: 0, failed: 0, recoverableErrors: 0, pending: new Set() }; } const islands = document.querySelectorAll("[data-mandu-island]"); const hydrated = document.querySelectorAll("[data-mandu-hydrated]"); const failed = document.querySelectorAll("[data-mandu-error]"); const recoverableErrors = document.querySelectorAll("[data-mandu-recoverable-error]"); const pending = new Set(); islands.forEach((el) => { const id = el.getAttribute("data-mandu-island"); if (id && !el.hasAttribute("data-mandu-hydrated") && !el.hasAttribute("data-mandu-error")) { pending.add(id); } }); return { total: islands.length, hydrated: hydrated.length, failed: failed.length, recoverableErrors: recoverableErrors.length, pending, }; } /** * ํŠน์ • Island unmount */ export function unmountIsland(id: string): boolean { const roots = getHydratedRoots(); const root = roots.get(id); if (!root) { return false; } root.unmount(); roots.delete(id); return true; } /** * ๋ชจ๋“  Island unmount */ export function unmountAllIslands(): void { const roots = getHydratedRoots(); for (const [id, root] of roots) { root.unmount(); roots.delete(id); } }