1+ 'use client' ;
2+
13import { ClerkRuntimeError } from '@clerk/shared/error' ;
24import { logger } from '@clerk/shared/logger' ;
35import type { ModuleManager } from '@clerk/shared/moduleManager' ;
@@ -8,12 +10,41 @@ import { isVersionAtLeast, parseVersion } from '@clerk/shared/versionCheck';
810import { type MountComponentRenderer , mountComponentRenderer } from './Components' ;
911import { MIN_CLERK_JS_VERSION } from './constants' ;
1012
13+ /**
14+ * Core rendering engine for Clerk's prebuilt UI components.
15+ *
16+ * `ClerkUI` bootstraps the component renderer that powers Clerk's drop-in
17+ * authentication and user-management components (`<SignIn />`, `<UserButton />`,
18+ * etc.). It is created internally by Clerk SDKs when the `ui` prop is passed to
19+ * `ClerkProvider` and should not be instantiated directly by application code.
20+ *
21+ * This module is marked `'use client'` so that React Server Components can
22+ * serialize `ClerkUI` as a client reference rather than attempting to serialize
23+ * the class itself.
24+ *
25+ * @public
26+ */
1127export class ClerkUI implements ClerkUIInstance {
1228 static version = PACKAGE_VERSION ;
1329 version = PACKAGE_VERSION ;
1430
1531 #componentRenderer: ReturnType < MountComponentRenderer > ;
1632
33+ /**
34+ * Creates a new `ClerkUI` instance and mounts the internal component renderer.
35+ *
36+ * Validates that the active `@clerk/clerk-js` version satisfies the minimum
37+ * required version ({@link MIN_CLERK_JS_VERSION}). In development instances a
38+ * mismatch throws a {@link ClerkRuntimeError}; in production it logs a warning.
39+ *
40+ * @param getClerk - Accessor that returns the active {@link Clerk} instance.
41+ * @param getEnvironment - Accessor that returns the current {@link EnvironmentResource}, or `null`/`undefined` if not yet loaded.
42+ * @param options - Global {@link ClerkOptions} forwarded to the component renderer.
43+ * @param moduleManager - The SDK's {@link ModuleManager} used for module resolution and lazy loading.
44+ * @throws {ClerkRuntimeError } When running in a development instance with an incompatible `@clerk/clerk-js` version.
45+ *
46+ * @internal
47+ */
1748 constructor (
1849 getClerk : ( ) => Clerk ,
1950 getEnvironment : ( ) => EnvironmentResource | null | undefined ,
@@ -50,6 +81,18 @@ export class ClerkUI implements ClerkUIInstance {
5081 this . #componentRenderer = mountComponentRenderer ( getClerk , getEnvironment , options , moduleManager ) ;
5182 }
5283
84+ /**
85+ * Ensures the UI component renderer is mounted and ready.
86+ *
87+ * Returns a promise that resolves with {@link ComponentControls} once the
88+ * renderer is fully initialised. Subsequent calls return the same promise.
89+ *
90+ * @param opts - Optional hints for the renderer.
91+ * @param opts.preloadHint - An optional component name to preload assets for (e.g. `"SignIn"`).
92+ * @returns A promise resolving to {@link ComponentControls} for mounting, unmounting, and updating components.
93+ *
94+ * @public
95+ */
5396 ensureMounted ( opts ?: { preloadHint ?: string } ) : Promise < SharedComponentControls > {
5497 return this . #componentRenderer. ensureMounted ( opts as unknown as any ) as Promise < SharedComponentControls > ;
5598 }
0 commit comments