/** * Hydration and runtime error reporting. * * The generated client entry passes React's `onRecoverableError`, * `onCaughtError`, and `onUncaughtError` a function that hands every report to * `globalThis.__RUVYXA_HYDRATION_REPORTER__` — or, until {@link hydrate} * installs one, queues it on `globalThis.__RUVYXA_HYDRATION_ERRORS__`. The * queue is what makes the API mean anything: hydration runs before any * application code can install a handler, so a mismatch reported straight to a * handler that did not exist yet was a mismatch nobody heard about, which is * what this used to be. * * The entry cannot import this package — an app may render plain React pages * and never install it — so the two halves meet on those two globals. The * writing side is `rootOptionsPrelude()` in * `packages/ruvyxa/runtime/entry-templates.mjs` and `ROOT_OPTIONS_PRELUDE` in * `crates/ruvyxa_bundler/src/output.rs`, held to one text by * `tests/packages/ruvyxa/entry-prelude-parity.test.mjs`; this module is the * only reader. */ /** Which React callback, or which caller, produced a report. */ export type HydrationErrorKind = 'recoverable' | 'caught' | 'uncaught' | 'manual'; /** What accompanies a reported error. */ export interface HydrationErrorContext { componentStack?: string; digest?: string; /** * `recoverable` is what a hydration mismatch is: React discarded the server * markup and rendered on the client. `caught` reached an error boundary; * `uncaught` reached none and unmounted the root. `manual` came from * {@link reportHydrationError}. */ kind?: HydrationErrorKind; } /** * Handler function for hydration errors. */ export type HydrationErrorHandler = (error: unknown, context: HydrationErrorContext) => void; /** * Options for the hydrate() helper. */ export interface HydrationOptions { /** The root element or document to hydrate into. */ root?: Element | Document; /** Custom error handler for hydration mismatches. */ onError?: HydrationErrorHandler; } /** * Signal that hydration is complete and register optional error handlers. * * Installing a handler also delivers every error React reported before this * call — the hydration mismatches themselves, which happen before any * application code runs. The handler is wrapped so that a failure inside it * never reaches React or the entry. * * Usage: * ```ts * import { hydrate } from "@ruvyxa/react" * * hydrate({ * onError: (error, { componentStack, kind }) => { * // Report to your error tracking service * myErrorService.captureException(error, { componentStack, kind }) * } * }) * ``` */ export declare function hydrate(options?: HydrationOptions): void; /** * Report an error through the registered handler. * * The generated entry reports React's own errors without going through here; * this is for application code that wants a failure of its own in the same * stream. With no handler installed yet the report is queued for the next * `hydrate({ onError })`, and in development it is also logged. */ export declare function reportHydrationError(error: unknown, context?: Omit): void; //# sourceMappingURL=hydration.d.ts.map