Vue and Solid adapters
The Vue and Solid adapters connect Zag state machines to each framework's reactive model and DOM rules. They keep machine state, context, events, controlled values, and element references in sync while exposing normalized props for framework templates and components. See the framework integrations page for the wider adapter model, and compare the React and Preact adapters and Svelte and Vanilla adapters.
Adapter role
The adapters provide the framework-facing boundary around a machine service. A component creates a service with useMachine, turns that service into a component API with a machine package's connect function, and applies the API's element props with the framework's own binding syntax.
This boundary keeps the machine packages framework-neutral. The machine decides what state and behavior an element needs. The adapter converts those needs into props, events, styles, children, and reactive updates that Vue or Solid can consume.
References: packages/…/index.ts• L1-4 packages/…/index.ts• L1-5 packages/…/toggle.connect.ts• L6-41
Shared machine flow
Both adapters follow the same product flow even though they use different reactive primitives. A machine service owns state and context, the connected API reads that service, and normalized props carry behavior to the DOM.
The following diagram shows how a machine request becomes framework output and how user events return to the machine.
flowchart LR
M[Machine definition] --> S[Framework service]
P[Machine props] --> S
S --> C[Machine connect API]
C --> N[Framework normalizeProps]
N --> V[Vue template or Solid JSX]
V --> E[User event]
E --> S
S --> R[Reactive state and context]
R --> C
The service starts with the framework lifecycle and stops with it. Before or during startup, the adapter can receive framework-owned input such as controlled values and IDs. After startup, events update the service and reactive state causes the connected API to expose current values.
References: packages/…/machine.ts• L30-37 packages/…/machine.ts• L242-270 packages/…/machine.ts• L30-37 packages/…/machine.ts• L238-295
Vue adapter
The Vue adapter is the Vue 3 entry point for machine services and normalized element props. It accepts plain props or Vue refs as machine input, then exposes service values through Vue-compatible reactive references and lifecycle hooks.
Vue machine state
@zag-js/vue creates one service for a component setup scope. The service uses Vue computed values for machine props and scope data, while bindable machine state uses shallow refs so controlled and uncontrolled values can both update the connected API. Vue mounts start the machine and replay events that arrive before the parent service is ready. Unmounting cleans up effects and runs the machine exit behavior.
The Vue input model supports three useful forms:
- Plain machine props for fixed setup values.
- A
ReforComputedReffor reactive props. - Bindable machine values with an external
valueandonChangepair for controlled state.
References: packages/…/machine.ts• L23-53 packages/…/machine.ts• L199-237 packages/…/machine.ts• L242-265 packages/…/bindable.ts• L5-37
Vue prop normalization
Vue normalization translates the common prop shape returned by a machine API into Vue DOM names. It maps event names and attributes such as className, htmlFor, onChange, and onDoubleClick, preserves selected SVG names, and turns string children into innerHTML.
Components normally pass the connected API through normalizeProps before using v-bind. This lets the machine package use one prop contract while Vue receives the names and child behavior expected by its template system.
References: packages/…/normalize-props.ts• L4-15 packages/…/normalize-props.ts• L22-43 packages/…/normalize-props.ts• L45-60 website/…/usage.mdx.hbs• L3-14
Vue element references
The Vue adapter gives machines a stable refs service for values that must survive reactive updates without becoming component state. Machine code can get or set a named reference, while the component supplies the resulting props to the relevant element through the connected API.
Vue-specific tracking uses watch to run machine effects when tracked values change. The adapter also exposes a shared-store bridge as a read-only shallow ref, so external snapshots update after mount and unsubscribe on unmount.
References: packages/…/refs.ts• L1-11 packages/…/track.ts• L1-20 packages/…/use-sync-external-store.ts• L1-23
Solid adapter
The Solid adapter is the Solid entry point for machine services and normalized JSX props. It accepts fixed props or an accessor that returns reactive props, then expresses machine state through Solid signals, memos, and ownership-aware cleanup.
Solid machine state
@zag-js/solid creates a service within the current Solid owner. It uses memos for machine props and scope data, signals for bindable state, and accessors for service snapshots. Mounting starts the machine. Cleanup removes effects and runs machine exit behavior.
The Solid input model supports two main forms:
- A plain props object for fixed setup values.
- An accessor for props that can change with Solid signals.
Bindable values can be controlled with an external value and change callback. Uncontrolled values stay in the adapter's signal until the machine reports a change.
References: packages/…/machine.ts• L25-51 packages/…/machine.ts• L196-234 packages/…/machine.ts• L238-257 packages/…/bindable.ts• L5-52
Solid prop normalization
Solid normalization translates machine API props into Solid JSX props. It maps common event and attribute names, removes a false readOnly value, converts style objects to CSS property names, and turns string children into textContent.
Components normally create a Solid memo around the connected API and spread normalized props onto JSX elements. The memo keeps API reads aligned with machine changes while normalizeProps keeps the machine contract independent from Solid's JSX names.
References: packages/…/normalize-props.ts• L5-27 packages/…/normalize-props.ts• L31-66 website/…/usage.mdx.hbs• L2-16
Solid element references
The Solid adapter provides a stable refs service with named get and set access. This supports machine data that must persist across updates without forcing that data into rendered JSX state.
Solid tracking uses createEffect to compare tracked values and run an effect after a change. Its external-store bridge returns a Solid accessor and removes the subscription through Solid cleanup.
References: packages/…/refs.ts• L1-11 packages/…/track.ts• L1-30 packages/…/use-sync-external-store.ts• L1-20
Framework reactive primitives
The adapters preserve the same machine contract but choose primitives that match each framework's update and ownership model. This difference matters when a component passes reactive props, reads service state, or relies on mount and cleanup behavior.
| Concern | Vue | Solid |
|---|---|---|
| Reactive machine props | Ref or ComputedRef input | Plain props or an Accessor input |
| Derived machine values | computed values and shallow refs | createMemo values and signals |
| Component startup | onMounted | onMount |
| Component cleanup | onBeforeUnmount and onUnmounted | onCleanup |
| External snapshot | Read-only ShallowRef | Read-only Accessor by convention |
| DOM prop application | v-bind after normalizeProps | JSX spread after normalizeProps |
These primitives are an adapter concern rather than a second machine model. A machine still sends events, reads context, exposes computed values, and returns connected element props in the same way in both frameworks.
References: packages/…/machine.ts• L23-37 packages/…/machine.ts• L242-265 packages/…/machine.ts• L25-37 packages/…/machine.ts• L238-257 packages/…/use-sync-external-store.ts• L3-22 packages/…/use-sync-external-store.ts• L3-19
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the prop names emitted by machine
connectAPIs compatible with both framework normalizers. A change that only matches Vue or Solid can silently break the other adapter. - Keep controlled bindable values aligned with their
value,onChange, equality, and initial-value rules. A mismatch can make the rendered value differ from the owning component. - Keep mount and cleanup behavior paired with external-store subscriptions and machine effects. Missing cleanup can leave updates or effects active after a component is gone.
- Keep changes to event or style translation in sync with the framework's DOM contract. Attribute spelling and child handling are part of the adapter boundary.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A machine API passes framework-specific prop names directly | Events or attributes do not work in the target template or JSX runtime | Pass element props through the target adapter's normalizeProps |
| A controlled value changes without its change callback updating the owner | The service reports a new value briefly, then returns to the old external value | Treat the external value as the source of truth and update it from onChange |
| A service sends events before Vue mount completes | The event can be lost or applied before the service is ready | Vue buffers pending events and replays them after mount; preserve this startup contract |
| A Solid event is sent after cleanup | The event is ignored while related effects or subscriptions can be mishandled if cleanup is bypassed | Keep service ownership inside the Solid owner and use onCleanup |
| A non-string child is passed through Vue normalization | The child is not rendered through the machine prop path and development warns | Render framework children in the template instead of passing them as machine children |
Key files
| File | Why to read it |
|---|---|
| packages/…/machine.ts | Main Vue service lifecycle, reactive state, event flow, and machine cleanup |
| packages/…/normalize-props.ts | Vue attribute, event, SVG, style, and child translation |
| packages/…/bindable.ts | Vue controlled and uncontrolled machine values |
| packages/…/use-sync-external-store.ts | Vue snapshot subscription behavior |
| packages/…/machine.ts | Main Solid service lifecycle, accessors, event scheduling, and cleanup |
| packages/…/normalize-props.ts | Solid JSX attribute, event, style, and child translation |
| packages/…/bindable.ts | Solid controlled and uncontrolled machine values |
| packages/…/use-sync-external-store.ts | Solid snapshot subscription behavior |
| packages/…/toggle.connect.ts | Small example of a machine API producing normalized element props and events |
website/plop/snippet/vue/usage.mdx.hbs | Standard Vue usage shape for service creation and v-bind |
website/plop/snippet/solid/usage.mdx.hbs | Standard Solid usage shape for service creation and JSX prop spreading |