diff --git a/apps/web/src/index.css b/apps/web/src/index.css index 2b19b90cc28e3..32c9f47479641 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -7,13 +7,31 @@ /* Window Controls Overlay: active when Electron exposes native titlebar control geometry. */ @custom-variant wco (&:is(.wco, .wco *)); -/* Secondary hovering pointers reveal sidebar actions on touch-primary devices. */ +/* Secondary hovering pointers reveal sidebar actions on touch-primary devices. + data-mouse-hover covers VDI/VM mice that Chromium reports as non-hovering (main.tsx). */ @custom-variant any-hover { @media (any-hover: hover) { &:hover { @slot; } } + &:where([data-mouse-hover] *):hover { + @slot; + } +} + +/* Tailwind gates hover on (hover: hover), which the same mice fail; without this every hover: + utility is inert there and hover-revealed controls stay invisible. Two branches cannot be + negated: not-hover: and not-any-hover: emit nothing. */ +@custom-variant hover { + @media (hover: hover) { + &:hover { + @slot; + } + } + &:where([data-mouse-hover] *):hover { + @slot; + } } /* On mobile, morph the expanded hero composer into the compact docked diff --git a/apps/web/src/main.test.ts b/apps/web/src/main.test.ts index 11b9b68c867d1..4a4371eddae9e 100644 --- a/apps/web/src/main.test.ts +++ b/apps/web/src/main.test.ts @@ -6,7 +6,10 @@ vi.mock("./i18n/runtime", () => ({ whenLocaleReady: async () => {} })); vi.mock("react-dom/client", () => ({ default: { createRoot: () => ({ render: () => {} }) } })); // Boots the entry in a fresh page that shares the tab's sessionStorage, as a reload does. -async function bootThenFailLazyChunk(sessionStorage: Map) { +async function bootMain( + { sessionStorage = new Map(), anyHover = true }, + interact: (page: EventTarget) => void, +) { vi.resetModules(); const reload = vi.fn().mockName("location.reload"); const page = Object.assign(new EventTarget(), { @@ -16,22 +19,59 @@ async function bootThenFailLazyChunk(sessionStorage: Map) { removeItem: (key: string) => sessionStorage.delete(key), }, location: { reload }, + matchMedia: (query: string) => ({ matches: query === "(any-hover: hover)" && anyHover }), }); + const root = { + marked: false, + toggleAttribute: (name: string, force: boolean) => root.setMarked(name, force), + removeAttribute: (name: string) => root.setMarked(name, false), + setMarked: (name: string, marked: boolean) => { + if (name === "data-mouse-hover") root.marked = marked; + }, + }; vi.stubGlobal("window", page); - vi.stubGlobal("document", { getElementById: () => ({}) }); + vi.stubGlobal("document", { getElementById: () => ({}), documentElement: root }); try { const { boot } = await import("./bootstrap"); await boot; - page.dispatchEvent(new Event("vite:preloadError", { cancelable: true })); - return reload; + interact(page); + return { reload, root }; } finally { vi.unstubAllGlobals(); } } +const failLazyChunk = (page: EventTarget) => + page.dispatchEvent(new Event("vite:preloadError", { cancelable: true })); + it("reloads only once when a lazy chunk fails after every boot", async () => { const sessionStorage = new Map(); - expect(await bootThenFailLazyChunk(sessionStorage)).toHaveBeenCalledTimes(1); - expect(await bootThenFailLazyChunk(sessionStorage)).not.toHaveBeenCalled(); + expect((await bootMain({ sessionStorage }, failLazyChunk)).reload).toHaveBeenCalledTimes(1); + expect((await bootMain({ sessionStorage }, failLazyChunk)).reload).not.toHaveBeenCalled(); }); + +it.each([ + { anyHover: false, input: "pointermove:touch pointermove:pen", marked: false }, + { anyHover: false, input: "pointermove:touch pointermove:mouse", marked: true }, + { anyHover: false, input: "pointermove:mouse pointermove:touch", marked: false }, + { anyHover: false, input: "pointermove:mouse pointerdown:mouse", marked: true }, + { + anyHover: false, + input: "pointermove:mouse pointerdown:touch pointerdown:mouse", + marked: false, + }, + { anyHover: true, input: "pointermove:mouse", marked: false }, +])( + "mouse hover marker is $marked with any-hover $anyHover after $input", + async ({ anyHover, input, marked }) => { + const { root } = await bootMain({ anyHover }, (page) => { + for (const event of input.split(" ")) { + const [type = "", pointerType] = event.split(":"); + page.dispatchEvent(Object.assign(new Event(type), { pointerType })); + } + }); + + expect(root.marked).toBe(marked); + }, +); diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx index 51aeeade6863d..244c6a07996e9 100644 --- a/apps/web/src/main.tsx +++ b/apps/web/src/main.tsx @@ -15,6 +15,25 @@ const router = startAppServices(); const clerkPublishableKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string | undefined; +// VDI/VM absolute pointers can report `any-hover: none` while delivering real mouse events. +// Capture phase: a handler that stops propagation must not hide the pointer type. +if (!window.matchMedia("(any-hover: hover)").matches) { + const root = document.documentElement; + const options = { capture: true, passive: true }; + window.addEventListener( + "pointermove", + (event) => root.toggleAttribute("data-mouse-hover", event.pointerType === "mouse"), + options, + ); + // A tap may never move, so presses clear the marker before its hover sticks. They never set + // it: the app replays synthetic mouse presses (HostedBrowserWebview). + window.addEventListener( + "pointerdown", + (event) => event.pointerType !== "mouse" && root.removeAttribute("data-mouse-hover"), + options, + ); +} + const app = ; // Split by runtime to keep Clerk out of local startup and clerk-js out of browser builds.