This folder contains the SSR-safe runtime logic for handling interactivity in React server components without using use client. It is designed to be tiny (~300 bytes), deterministic, and fully compatible with React Zero-UI's pre-rendered data-attribute model.
This is the core runtime entrypoint. When called:
-
Registers a single global click event listener on
document. -
Listens for clicks on any element (or ancestor) with a
data-uiattribute. -
Parses the
data-uidirective with this format:data-ui="global:key(val1,val2,...)"-> flipsdata-keyondocument.bodydata-ui="scoped:key(val1,val2,...)"-> flipsdata-keyon closest matching ancestor or self
-
Cycles the value of the matching
data-*attribute in a round-robin fashion. -
Updates the DOM instantly, enabling Tailwind to respond via selectors (e.g.
theme-dark:bg-black).
It guards against duplicate initialization using a window.__zero flag.
These utility functions generate valid data-ui attributes for use in JSX/TSX.
They return a prop like this:
{ 'data-ui': 'global:theme(dark,light)' }or
{ 'data-ui': 'scoped:modal(open,closed)' }In development, they also perform validation:
- Ensures the key is kebab-case.
- Ensures at least one value is provided.
- No React state or re-renders involved.
- Works entirely via DOM
data-*mutations. - Compatible with all server components.
- Fully tree-shakable and side-effect-free unless
activateZeroUiRuntime()is called.
This design makes it ideal for pairing with Tailwind-style conditional classes in static components.
activateZeroUiRuntime()-> enables click handling on static components viadata-uizeroSSR/scopedZeroSSR-> emit valid click handlers as JSX props- No state. No runtime overhead. Works in server components.
This runtime is the bridge between static HTML and interactive UX, while keeping everything server-rendered and blazing fast.