Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(play-a11y): land dialog focus immediately, not only on the next frame

nirholas572a326fcdd9
diff --git a/src/game/a11y.js b/src/game/a11y.js
index cdeef09da..073bddd0a 100644
--- a/src/game/a11y.js
+++ b/src/game/a11y.js
@@ -130,11 +130,20 @@ export function trapFocus(root, { initialFocus } = {}) {
// the panel's async content arrives; -1 keeps it out of the Tab order.
if (!root.hasAttribute('tabindex')) root.setAttribute('tabindex', '-1');
const target = initialFocus || focusableIn(root)[0] || root;
- // Defer one frame: panels focus-trap in their constructor, before the card
- // has been laid out, and focusing a zero-size element is a silent no-op.
- requestAnimationFrame(() => {
+ const applyFocus = () => {
if (root.isConnected) try { target.focus({ preventScroll: true }); } catch { /* detached */ }
- });
+ };
+ // Twice, on purpose. The next-frame call is what handles the common case:
+ // panels focus-trap in their constructor, before the card has been laid out,
+ // and focusing a zero-size element is a silent no-op. But a frame is not
+ // guaranteed to arrive on demand - /play drives rAF off a WebGL compositor
+ // that stalls under load, and a backgrounded tab stops delivering frames
+ // altogether - and a deferred-only focus leaves `aria-modal` promising a trap
+ // that never closed, with the keyboard still on the page behind the dialog.
+ // Focusing now costs nothing when it no-ops and holds the promise when no
+ // frame ever comes.
+ applyFocus();
+ requestAnimationFrame(applyFocus);
let released = false;
return () => {