Skip to content

Vizel API / core/src / vizelThemeInitScript

Function: vizelThemeInitScript()

ts
function vizelThemeInitScript(options?): string;

Defined in: packages/core/src/utils/ssr.ts:48

Build a synchronous theme-initialization script for embedding in the document <head>.

The script reads the stored theme (falling back to the configured default) and sets data-vizel-theme on document.documentElement before the page paints. Inserting the result inline in a server-rendered <head> eliminates the dark-mode flash that otherwise appears on the first paint when the client mounts with the wrong theme.

The script touches only document.documentElement — Vizel's other code stays scoped to the editor wrapper, per the theme policy. The output is a self-contained IIFE that the framework adapter places inside a <script> tag using the framework's idiomatic inline-script mechanism.

The script body is fully synthesized from typed options inside this helper and never embeds consumer-supplied raw markup, so it carries no XSS surface.

Parameters

ParameterType
optionsVizelThemeInitScriptOptions

Returns

string

Released under the MIT License.