Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge pull request #5222 from dewly-justice/fix/overlay-layer
milind-soniead8fe935779
diff --cc src/components/AppNotices.test.tsindex 1b1bc1d829,618e546868..b41b6e3b4d--- a/src/components/AppNotices.test.ts+++ b/src/components/AppNotices.test.ts@@@ -15,8 -15,8 +15,9 @@@ import { createUpdatesConsent, registerconst f = vi.hoisted(() => ({ values: [] as unknown[], index: 0, effects: [] as EffectCallback[], state: {} as any, updater: null as any, dispatch: null as any, brand: "default",viewerEmail: undefined as string | null | undefined }));+ vi.mock("./Layer", () => ({ Layer: ({ children }: { children: ReactNode }) => children, useIsTopLayer: () => () => true }));vi.mock("react", async original => ({ ...await original<typeof import("react")>(),+ useId: () => "test-id",useState: (initial: unknown) => { const index = f.index++; if (!(index in f.values)) f.values[index] = typeof initial === "function" ? initial() : initial;return [f.values[index], (next: unknown) => { f.values[index] = typeof next === "function" ? (next as (value: unknown) => unknown)(f.values[index]) : next; }]; },useEffect: (effect: EffectCallback) => { f.effects.push(effect); },diff --cc src/components/PhoneDevicesSection.tsxindex 32cb2d422f,6ddcffdcc2..3c582873eb--- a/src/components/PhoneDevicesSection.tsx+++ b/src/components/PhoneDevicesSection.tsx@@@ -21,6 -20,8 +20,7 @@@ import { revealPhonePairing } from "../import { PhonesList } from "./PhonesList";import { PairedPhones } from "./PairedPhones";import { Card, Switch } from "./SettingsPrimitives";+ import { Layer } from "./Layer";-import { useModalDialog } from "../hooks/use-modal-dialog";import { productName } from "../lib/brand";import { useStore } from "@/state/store";@@@ -232,34 -226,9 +232,34 @@@ export function PairDeviceDialog({ c, ssetStep("pairing");c.useLocal();};- return <Layer modal>- <div ref={dialog} tabIndex={-1} role="dialog" aria-modal="true" aria-label={step === "consent" ? t("devices.pair.title") : t("devices.pair.titlePhone")}- className="fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4 outline-none" data-pair-dialog={step}>+ const close = step === "consent" ? onClose : () => { c.cancel(); onClose(); };+ const root = useRef<HTMLDivElement>(null);+ useEffect(() => {+ const before = document.activeElement instanceof HTMLElement ? document.activeElement : null;+ const box = root.current;+ if (box && !box.contains(document.activeElement)) box.querySelector<HTMLElement>(FOCUSABLE)?.focus();+ return () => { if (before?.isConnected) before.focus(); };+ }, []);+ // Settings also handles Escape and Tab; capture them first so they act on this dialog only.+ useEffect(() => {+ const onKey = (event: KeyboardEvent) => {+ const box = root.current;+ if (!box || event.defaultPrevented || event.isComposing || (event.key !== "Escape" && event.key !== "Tab")) return;+ event.preventDefault();+ if (event.key === "Escape") { close(); return; }+ const controls = [...box.querySelectorAll<HTMLElement>(FOCUSABLE)].filter((control) => control.getClientRects().length);+ if (!controls.length) return;+ const at = controls.indexOf(document.activeElement as HTMLElement);+ const next = at < 0 ? (event.shiftKey ? -1 : 0) : at + (event.shiftKey ? -1 : 1);+ controls.at(next % controls.length)!.focus();+ };+ window.addEventListener("keydown", onKey, true);+ return () => window.removeEventListener("keydown", onKey, true);+ }, [close]);- // An ancestor with backdrop-filter becomes the containing block for `fixed`, so render into the body.++ // An ancestor with backdrop-filter becomes the containing block for `fixed`, so it renders through Layer, on the body.+ const dialog = (+ <div ref={root} role="dialog" aria-modal="true" aria-label={step === "consent" ? t("devices.pair.title") : t("devices.pair.titlePhone")}+ className="fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4" data-pair-dialog={step}><div className="flex max-h-full w-full max-w-[460px] flex-col gap-4 overflow-y-auto rounded-2xl bg-card p-5 shadow-xl"><div className="text-[15px] font-semibold text-ink">{step === "consent" ? t("devices.pair.title") : t("devices.pair.titlePhone")}</div>{step === "consent" ? (@@@ -295,8 -264,7 +295,8 @@@)}</div></div>- </Layer>;+ );- return typeof document === "undefined" ? dialog : createPortal(dialog, document.body);++ return <Layer modal>{dialog}</Layer>;}/** A pairing code still open: anyone holding it can pair until it runs out, so it can be revoked here. */diff --cc src/components/SettingsModal.search.test.tsindex 3ae1f7dfb0,746a8dfd31..e7e68591c4--- a/src/components/SettingsModal.search.test.ts+++ b/src/components/SettingsModal.search.test.ts@@@ -70,29 -70,18 +70,29 @@@ describe("Settings search in Simple modexpect(search().value).toBe("f");});- it("points nowhere Advanced, Simple being the only mode, and finds Automatic recovery under More settings", () => {- for (const words of ["font", "chat width", "circles", "universal", "this run"]) {+ it("lists a builder control as Advanced and, when chosen, opens General at the Advanced mode row", () => {+ type("font");- const result = host.querySelector<HTMLButtonElement>('[data-settings-advanced-only="settings.font.title"]')!;++ const result = document.querySelector<HTMLButtonElement>('[data-settings-advanced-only="settings.font.title"]')!;+ expect(result.textContent).toBe("Interface font · Advanced");+ flushSync(() => result.click());+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "toggleAppSettings", open: true, section: "general" });+ expect(scrolled.map((element) => element.getAttribute("data-settings-block"))).toContain("advanced-mode");+ expect(search().value).toBe("");+ });++ it("finds every other builder control as Advanced, and Automatic recovery under More settings", () => {+ for (const [words, key] of [["chat width", "settings.chatWidth.title"], ["circles", "settings.pinnedCircles.title"],+ ["universal", "settings.universalPins.title"], ["this run", "settings.runCard.title"]]) {type(words);- expect(host.querySelector(`[data-settings-advanced-only="${key}"]`)?.textContent, words).toMatch(/ · Advanced$/);- expect(document.querySelector("[data-settings-advanced-only]"), words).toBeNull();- expect(dialog().textContent, words).not.toContain("· Advanced");++ expect(document.querySelector(`[data-settings-advanced-only="${key}"]`)?.textContent, words).toMatch(/ · Advanced$/);}type("recovery");- expect(host.querySelector("[data-settings-advanced-only]")).toBeNull();- const result = host.querySelector<HTMLButtonElement>('[data-settings-more-result="settings.recovery.title"]')!;++ expect(document.querySelector("[data-settings-advanced-only]")).toBeNull();+ const result = document.querySelector<HTMLButtonElement>('[data-settings-more-result="settings.recovery.title"]')!;expect(result.textContent).toBe("Automatic recovery · More settings");flushSync(() => result.click());- expect(host.querySelector("h2")!.textContent).toBe("More settings");- expect(host.querySelector('[data-settings-block="limits"]')!.textContent).toContain("Automatic recovery");+ expect(document.querySelector("h2")!.textContent).toBe("More settings");+ expect(document.querySelector('[data-settings-block="limits"]')!.textContent).toContain("Automatic recovery");expect(scrolled.map((element) => element.getAttribute("data-settings-block"))).toContain("limits");expect(search().value).toBe("");});