@gluonjs/atoms


@gluonjs/atoms / packages/atoms/src / createUiStyleSelection

Function: createUiStyleSelection()

createUiStyleSelection(theme?): UiStyleSelection

Returns the exact ordered shared UI selection used by SSR and hydration.

Parameters

theme?

UiThemeName = 'light'

Returns

UiStyleSelection

Example

Create the exact named shared layer, foundation, token, and selected-theme input used by server rendering:

ts
import {
  UiHydrationError,
  createUiStyleSelection,
  installUi,
  type InstallUiOptions,
  type UiHydrationMismatch,
  type UiOwner,
  type UiStyleSelection,
} from '@gluonjs/atoms';

const options = { theme: 'dark', hydrate: false } satisfies InstallUiOptions;
const selection: UiStyleSelection = createUiStyleSelection(options.theme);
const owner: UiOwner = installUi(document, options);
owner.setTheme('light');
console.log(selection.entries.map((entry) => entry.id), owner.theme, owner.themeSheet);
owner.dispose();

const mismatch: UiHydrationMismatch = 'missing';
const diagnostic = new UiHydrationError(mismatch, 'The server omitted the UI theme carrier.');
console.error(diagnostic.code, diagnostic.mismatch);