A desktop typing test wants the keyboard ready the moment the page loads. On a phone, focusing an input opens the on-screen keyboard, which covers half the screen before the reader has decided to type. Typestrix runs the same typing engine on both, and changes only the focus policy around it.
A real input under custom text
The passage is a set of character spans. Over it sits a real <input type="text"> with opacity-0 and inset-0, covering the whole text area. That input receives every key, opens the mobile keyboard, and fires change events; the spans and the separate caret only draw.
<input
className="absolute inset-0 cursor-default opacity-0"
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck={false}
inputMode="text"
/>
Autocomplete, autocorrect, auto-capitalisation and spellcheck are all off because each one changes the text being measured. Because the input covers the passage, "tap the text" and "tap the input" are the same gesture, and that tap is what lets the browser open the keyboard.
Two policies, one engine
isTouchPrimary() matches phones and tablets: no hover and a coarse pointer. A touchscreen laptop with a mouse or trackpad does not match, so it gets the desktop policy.
| Moment | Desktop | Touch-primary |
|---|---|---|
| Page load | Focus input on the next frame | Nothing; show the tap cue |
| Click or tap on empty page | Refocus input | Nothing; keyboard may close |
| Tap a button, link, tab, switch | Refocus just after the press (the click still lands) | Nothing; keyboard closes |
| Input loses focus | Refocus on the next frame | Nothing |
| Hardware key pressed elsewhere | Refocus input | Refocus input (tablet keyboards) |
| Restart | Always refocus | Refocus only if the input was focused |
On desktop, useInputFocus installs mousedown, touchstart, keydown and input blur listeners on the document and pulls focus back on every one, so you can click anywhere and keep typing. On touch it installs only the keydown listener. Without that split, tapping "Test Settings" would focus the input again and the keyboard would pop straight back up over the sheet.
The first-visit journey on a phone
Pick a step, or use the arrows, to walk through the diagram.
Load the phone UI only for phones
Below the sm breakpoint the mode bar collapses into a single "Test Settings" button. The sheet behind it is a next/dynamic import with ssr: false, and it is not even rendered until the first pointerdown on the button. Desktop users never download its code. The site settings panel, room settings and profile editor also load their mobile drawers with next/dynamic.
useMediaQuery subscribes to matchMedia with useSyncExternalStore and returns false from its server snapshot. The server never touches window, and the first client render agrees with the server HTML before switching to the real value.
Restart reads the keyboard state first
const refocus = !isTouchPrimary() || document.activeElement === inputRef.current;
requestAnimationFrame(() => {
resetCaretPosition();
if (inputRef.current) {
if (refocus) inputRef.current.focus();
inputRef.current.setSelectionRange(0, 0);
inputRef.current.value = "";
}
});
The decision is taken before the frame, while the old input is still focused (or not). A restart while typing keeps the keyboard; a restart from the results screen or the settings sheet does not reopen it.
Integrity rules versus mobile keyboards
Signed-in tests reject paste, drops, and any single change that adds more than one character. Mobile keyboards often commit a whole word or a suggestion in one event (composition), and those commits are rejected too. Autocorrect being off reduces how often that happens, but some keyboards ignore the attribute.
That policy fits English character-by-character tests. It is not a complete answer for input methods that legitimately insert several characters at once (Chinese, Japanese, Korean IMEs, swipe typing). A multi-character insert is not proof of cheating; it is just not supported by these tests.
Guest practice is more permissive: paste and composition checks are off, while drop and context-menu blocking stay on for everyone.
The engine never needed to know it was on a phone. Every difference lives at the edges, in when focus is taken and when it is left alone, and every keyboard change follows something the user actually did.