Building a WebXR UI kit on Vue and TresJS
Aleksandr Ovchinnikov · December 2026 · Русская версия
I have spent years building UI kits and design systems for the web in Vue. To move into XR, I built one more, this time for the headset: vue-xr-ui, a Vue 3 component library for VR and mixed-reality interfaces that runs in the Meta Quest 3 browser, in PC VR and on a regular screen with a mouse.
<XrWindow :position="[0, 1.4, -0.9]" snap anchor="main">
<XrText variant="headline">Living room</XrText>
<XrToggle v-model="lights">Lights</XrToggle>
<XrSlider v-model="brightness" :min="0" :max="100" />
<XrButton @click="scene('movie')">Movie night</XrButton>
</XrWindow>That window can be grabbed and carried, snaps to a wall in passthrough, remembers where you left it across sessions, and every control in it works with a mouse, a controller ray, a hand pinch and a fingertip poke. Version 1.0 is on npm with 28 components, docs with live demos, a mixed-reality demo app and over a hundred end-to-end tests that run in an emulated Quest 3 on every push.
This article is about how it is built and what was hard. Most of the hard parts were not where I expected.
The stack, and why not from scratch
The web XR stack has three layers, and I wrote none of them:
- three.js renders, and TresJS is a Vue custom renderer for it:
<TresMesh>in a template becomes aMeshin the scene. It is to Vue what react-three-fiber is to React. - @pmndrs/uikit is a UI engine for three.js: yoga flexbox layout, MSDF text, instanced panels. A whole window is a few draw calls.
- @pmndrs/xr owns the WebXR session and turns every input into DOM-like pointer events: rays from controllers and hands, a grab sphere, and a touch (poke) sphere on each index fingertip.
A UI kit's value is not drawing rectangles. It is the layer on top: what a "press" means, how focus moves, how a popup escapes a scrolling list, what size a target must be to poke it, and making all of that feel like Vue. That is what vue-xr-ui is.
Vue app (DOM) <XrEnterButton>, useXr()
└─ createXrUi() plugin app-wide XR controller + theme
└─ <TresCanvas> TresJS: Vue renderer for three.js
└─ <XrScene> @pmndrs/xr store, XR-safe frame loop
└─ <XrPanel> uikit root: yoga flexbox, MSDF text
├─ <XrText>
└─ <XrButton>Units: designing in millimetres you see
On a screen a pixel is a pixel. In a headset, text 2 cm tall is huge at half a metre and unreadable at five. So every size in the kit is in dmm: one millimetre seen from one metre away, an angle rather than a length. A panel placed 2 m away is scaled 2x and reads exactly the same.
Design tokens are in dmm (fontSize: 18 is body text, about one degree of view, some 25 headset pixels on a Quest 3), and so is the smallest target, theme.interaction.minTarget, sized for a fingertip rather than a cursor. Scene positions stay in metres. This one decision made themes portable: a designer can reason about a panel without knowing where the app will put it.
Binding a UI engine to Vue
Components are defineComponent and h() in .ts files, no SFCs. Each one owns a uikit node through two helpers:
// XrButton, simplified
const press = usePress({ disabled: () => props.disabled, onPress: (e) => emit('click', e) })
const { node, render } = useUikitNode(
(initial) => new Container(initial),
() => ({ ...theme.button[props.variant], ...pressHandlers(press), ...props.ui }),
)The interesting part is what the binding had to work around:
- Only roots go through TresJS. TresJS wraps
<primitive>objects in a Proxy. If nested uikit nodes went through it,child.parentbecame the Proxy and uikit treated every child as a separate layout root. So a root panel renders as<primitive :object>, and every nested node callsparent.add(node)directly. - Template order. uikit lays flex children out in
parent.childrenorder. A child that appears later throughv-ifis appended, so it jumped to the end of the row. The binding now walks the owner's vnode tree, re-sortsparent.childrenin place into template order and asks for a layout pass. app.providedoes not cross. TresJS mounts the scene as a separate Vue app, which does not see the main app'sprovide. Plugin state lives in a registry keyed byappContext.appinstead.- Every component takes
ui(raw uikit props merged last) and, where it has parts,parts. For a completely different look there are headless composables (useXrSlider,useXrSelect,useXrPress...) that keep the behaviour and leave the drawing to you, the same split as in headless web UI libraries.
One press for every input
This is the core of the kit. A button must respond the same way to:
- a mouse on a desktop screen,
- a controller ray and its trigger,
- a hand ray and a pinch,
- a fingertip poke: the finger physically pushes into the button.
@pmndrs/xr gives all four as pointer events, but its click is DOM-faithful in the wrong way for a headset: it fires only if pointerup comes within 300 ms. A slow, careful poke or a held trigger was simply lost. So every control uses one usePress:
- A press counts on release, however long it is held. Down, then up from the same
pointerId, is a click. - The control captures the pointer on down, like DOM pointer capture for touch. Pressing sinks the button visually, which can move it out from under a ray or a fingertip for a frame; the release must still land on it.
- A drag never selects. Inside a scrolling list, the press is cancelled once the pointer travels a few millimetres along the surface, so scrolling with a finger does not tap the row it started on. "Along the surface" matters: a poking finger moves into the panel, and that depth must not count as travel.
Then came the conflicts between pointers that a mouse never has:
- Grab vs poke. A tracked hand carries a grab sphere and a touch sphere on the same fingertip. When both hit a button at the same distance, grab wins, and a poke never pressed anything. UI roots now deny grab pointers (
pointerEventsType: { deny: 'grab' }): grabbing is for objects, not for buttons. - Presses in the void. Sphere pointers report a
pointerdownon the "void" object whenever nothing is near the hand. Any "press outside closes the popup" logic has to ignore those, or a select closes the moment you reach for it. - zIndex moves hit tests. In uikit each
zIndexstep also subtracts 1 cm from the pointer distance, so a fingertip "touched" a popup withzIndex: 10ten centimetres before reaching it. Popups draw on top withrenderOrderinstead.
Keyboard navigation goes through the same path: the canvas takes focus, Tab walks registered controls in scene order (skipping hidden, disabled and outside-the-open-dialog ones), and Enter or Space activates the focused control with the same click.
Popups that escape a scrolling list
A dropdown inside a scrolling container gets clipped by it, as on the web. On the web you portal it to <body>; in a 3D scene there is no body. The answer was a popup layer: the select's list is a uikit layout root of its own, positioned every frame at its anchor's world position, drawn over the content with renderOrder, and closed when the anchor scrolls out of view. The same mechanism is behind tooltips.
An on-screen keyboard
Typing is where XR UIs usually give up. <XrKeyboard> has six built-in layouts (EN, RU, UK, DE, FR, ES) plus your own, a ?123 page, Shift (double tap for caps lock), a held Backspace that repeats, and a microphone key. It types into the last focused <XrTextField>, which has a real caret you can tap to move.
Lessons it taught:
- Fonts. uikit's bundled fonts are Latin only, so Cyrillic rendered as nothing. The kit ships Inter with Latin and Cyrillic as MSDF atlases, built by a script, about 250 KB per weight, loaded on first use.
- Timers lie. In the emulator (where a software-rendered frame takes 100 to 200 ms) and on a busy headset, timers fire late, so a held Backspace that repeated per timer tick deleted far fewer letters than it should. Anything that repeats while held now counts from the clock, not from ticks.
- Voice is pluggable. By default the mic key uses the Web Speech API in the active layout's language, and hides itself where there is none.
:voice="recordingRecognizer(transcribe)"records the microphone and sends audio to your own speech-to-text (a Whisper endpoint, a cloud service).
Testing a headset UI without a headset
I could not put a Quest in CI, so CI runs an emulated one. IWER, Meta's WebXR emulation runtime, pretends to be a Quest 3 in headless Chromium: a head, two controllers or two tracked hands, with joints.
The playground mounts a dev-only TestHook that exposes window.__xrTest: find a control by its label, project it to screen pixels, point a controller at it, move a fingertip into it. On top of it, Playwright specs read like a user story:
test('a fingertip taps the toggle and slides the slider', async ({ scene }) => {
await scene.setInputMode('hand')
await scene.poke('right', 'Sound')
await scene.expectText('Muted')
await scene.poke('left', '#volume.track', 0.4, 0.2)
await scene.expectText('Volume: 20')
})Every control is covered with mouse, ray and hand poke. The suite also checks a draw-call budget, keyboard navigation, focus trapping in dialogs, reduced motion, tracking loss, and anchors that survive a reload. CI collects coverage from both the unit and e2e runs.
The emulator was its own source of bugs:
- Injection. @pmndrs/xr's built-in emulator calls IWER's
installRuntimewithoutforceInstall, and IWER 2.3+ then skips desktop Chrome, which already hasnavigator.xr. The kit injects IWER itself (createXrEmulator()fromvue-xr-ui/emulator). - Frames are late. A pointer sees a hand move one or two XR frames later, so the helpers count real XR frames instead of sleeping.
- CI is slower than my laptop. Several times slower to render. Every assertion right after an input polls; none reads state once.
What only the headset showed
The emulator proves the logic. The Quest shows what it feels like, and some bugs exist only there:
- Blurry text. The Quest browser's default framebuffer is smaller than the display, and three.js turns on maximum fixed foveation by default.
<XrScene>asks for native resolution and turns foveation off. What remains is physics: about 25 pixels per degree, two to four times fewer than a laptop at arm's length, so the theme's text is sized for that. - Panels vanished from behind. Walk around a window and it was gone. uikit forces
FrontSideon its panel material right after creating it, so assignments were ignored; the fix pinsDoubleSideon a material subclass's prototype, for root backgrounds only, so text never shows through mirrored. - A frozen hand under your head. When a hand leaves the cameras' view, Quest keeps its input source and a guessed ray pose, but the joints lose theirs. @pmndrs/xr kept showing the hand, frozen, hanging below the head with a live ray. A tracking guard now hides an input and stops its pointers until its ray, wrist and grip all have a pose again.
- Getting out. With hands only, the system gesture to leave a session proved unreliable.
<XrExitButton>and<XrSessionMenu>(a palm pinch asks "Leave VR?") give apps a way out they control. - The loop ran twice. TresJS drives its loop with window
requestAnimationFrame, which stops inside an XR session, so the scene switches torenderer.setAnimationLoop. But three.js restarts its own window loop on everysetAnimationLoopcall and stops it only onsessionstart. Called mid-session, the UI updated and rendered twice per frame wherever window rAF keeps running (PC VR, the emulator). It is now set once at setup and ignores ticks outside a session. - An XRFrame expires. Persistent anchors need the current
XRFrame. Awaiting something and then using the frame failed: the frame is valid only inside its callback. Anchor work is queued and done in the next frame callback. - Where is the head? Before render, three.js leaves the XR camera at the first eye's pose, so everything that turned to face "the viewer" was 2 degrees off. The head is the midpoint of the eyes.
Every one of these is now a line in the repository's CLAUDE.md "Gotchas already paid for", so nobody pays for it twice.
Mixed reality
In passthrough the room is the background, and UI should live in it:
<XrWindow snap>sticks to walls and tables found by plane detection,anchor="name"stores a persistent anchor, so a window stays where you left it across sessions and reloads,<XrFollow>keeps content in view and lazily follows head turns,<XrHandMenu>shows a menu above your palm when you turn it toward your face, poked with the other hand.
The demo app puts it together: a smart-home dashboard for Home Assistant (or a demo home) that you pin around your real room.
How the project is run
It is a solo project, so the process is lightweight but strict:
- Plan as code.
roadmap.ymlholds the definition of done and the milestones; a workflow syncs it to GitHub issues and a project board. - Definition of done per change: typecheck and build, e2e for mouse, ray and poke, JSDoc on every public prop (the docs build fails without it: the API tables are generated from the source), a docs page, a changeset.
- Releases with changesets and npm trusted publishing from CI, no tokens.
- A journal. After every task: what was done, how, what was learned, what is next. It is the project's memory and the source of this article.
I built it together with an AI coding agent (Claude Code), which wrote much of the code under these rules. My job was the product and API decisions, the review, and the part no agent can do: putting on the headset and noticing that a hand is hanging under my chin.
What I would tell someone starting
- Design the press first. Everything else in an XR UI kit sits on what "press" means for four kinds of pointers.
- Measure in angles, not metres. dmm made every other size decision easy.
- Test in an emulator, judge in the headset. The emulator caught regressions every day; the headset found every bug that mattered to people.
- Read the library source. Half of the fixes above came from reading three.js, uikit and @pmndrs/xr, not their docs.
Links
- Docs and live demos: vue-xr-ui.vercel.app
- Demo app (MR smart home): vue-xr-ui-home.vercel.app
- Playground (open in the Quest browser): vue-xr-vr.vercel.app
- Source: github.com/ovchinnikov-lxs/vue-xr-vr
- npm: vue-xr-ui