From d51fb4d81a4106890af995b6e356ba7ca1bb4384 Mon Sep 17 00:00:00 2001
From: peter
Date: Mon, 23 Nov 2026 10:55:09 +0100
Subject: [PATCH 1/2] fix(web): hover styles work for mice reported as
non-hovering
Some VDI, VM and VNC setups expose the mouse as an absolute pointer, and
Chromium (notably inside Electron) then reports `hover: none` and
`any-hover: none` while still delivering `pointerType: "mouse"` events.
Every `hover:` and `any-hover:` utility is gated on those media queries,
so hover-revealed controls such as the sidebar row actions and the
assistant response toolbar never appear.
The `hover` and `any-hover` variants now match `:hover` under
`data-hover` / `data-any-hover` markers on . main.tsx keeps each
marker in sync with its media query, and on machines that report no
hovering pointer also sets them while the last pointer was a mouse
(touch, pen and non-mouse presses clear it). A single selector per
variant keeps one CSS rule per utility instead of emitting a media rule
plus a fallback rule.
Co-authored-by: donpimponnousacondom-afk <276086757+donpimponnousacondom-afk@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5
---
apps/web/src/index.css | 13 ++++------
apps/web/src/main.test.ts | 52 ++++++++++++++++++++++++++++++++++-----
apps/web/src/main.tsx | 42 ++++++++++++++++++++++++++++---
3 files changed, 89 insertions(+), 18 deletions(-)
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index 15380512f4060..e55d651a41325 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -7,14 +7,11 @@
/* 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. */
-@custom-variant any-hover {
- @media (any-hover: hover) {
- &:hover {
- @slot;
- }
- }
-}
+/* Hover variants key off markers main.tsx keeps on : the media query's answer, or a real
+ mouse that Chromium reports as non-hovering (VDI/VM absolute pointers). A single selector keeps
+ one rule per utility. Without main.tsx (e.g. browser tests importing this file) hover never matches. */
+@custom-variant hover (&:where([data-hover] *):hover);
+@custom-variant any-hover (&:where([data-any-hover] *):hover);
/* On mobile, morph the expanded hero composer into the compact docked
composer while it moves; the rest of the app remains visually stationary. */
diff --git a/apps/web/src/main.test.ts b/apps/web/src/main.test.ts
index 11b9b68c867d1..d4790542f1670 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: anyHover && query.endsWith("hover: hover)"),
+ addEventListener: () => {},
+ }),
});
+ const root = {
+ attributes: new Set(),
+ toggleAttribute: (name: string, force: boolean) =>
+ force ? root.attributes.add(name) : root.attributes.delete(name),
+ };
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:touch", marked: true },
+])(
+ "hover markers are $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.attributes].toSorted()).toEqual(marked ? ["data-any-hover", "data-hover"] : []);
+ },
+);
diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx
index 2640ca1e167d0..a6b3a1fbf1a9a 100644
--- a/apps/web/src/main.tsx
+++ b/apps/web/src/main.tsx
@@ -4,7 +4,6 @@ import ReactDOM from "react-dom/client";
import "@fontsource-variable/inter";
import "./index.css";
-import { trackKeyboardLayout } from "./keyboardLayout";
import { hasCloudPublicConfig } from "./cloud/publicConfig";
import { isElectron } from "./env";
import { startAppServices } from "./appInit";
@@ -12,13 +11,48 @@ import { AppRoot } from "./AppRoot";
import { whenLocaleReady } from "./i18n/runtime";
import { chunkLoadState } from "./lib/chunkReloadGuard";
-const stopTrackingKeyboardLayout = trackKeyboardLayout();
-import.meta.hot?.dispose(stopTrackingKeyboardLayout);
-
const router = startAppServices();
const clerkPublishableKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string | undefined;
+// index.css gates hover variants on these markers instead of media queries, so a VDI/VM mouse that
+// Chromium reports as non-hovering can set them too.
+const root = document.documentElement;
+const hoverMarkers = [
+ ["data-hover", window.matchMedia("(hover: hover)")],
+ ["data-any-hover", window.matchMedia("(any-hover: hover)")],
+] as const;
+let lastPointerIsMouse = false;
+const syncHoverMarkers = () => {
+ for (const [name, query] of hoverMarkers) {
+ root.toggleAttribute(name, query.matches || lastPointerIsMouse);
+ }
+};
+for (const [, query] of hoverMarkers) query.addEventListener("change", syncHoverMarkers);
+syncHoverMarkers();
+
+if (!hoverMarkers[1][1].matches) {
+ const setLastPointer = (isMouse: boolean) => {
+ if (isMouse === lastPointerIsMouse) return;
+ lastPointerIsMouse = isMouse;
+ syncHoverMarkers();
+ };
+ // Capture phase: a handler that stops propagation must not hide the pointer type.
+ const options = { capture: true, passive: true };
+ window.addEventListener(
+ "pointermove",
+ (event) => setLastPointer(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" && setLastPointer(false),
+ options,
+ );
+}
+
const app = ;
// Split by runtime to keep Clerk out of local startup and clerk-js out of browser builds.
From f59c84036de9cfb64fcba654749b1acdbc060929 Mon Sep 17 00:00:00 2001
From: peter
Date: Mon, 23 Nov 2026 11:17:41 +0100
Subject: [PATCH 2/2] fix(web): keep keyboard layout tracking and recover hover
after media changes
Restore the trackKeyboardLayout() startup call that the previous commit
dropped by mistake.
Attach the pointer listeners unconditionally and apply the mouse
fallback only while `any-hover` is false, so a device whose `any-hover`
flips to none after boot can still recover hover via a real mouse.
Co-Authored-By: Claude Opus 5.5
---
apps/web/src/main.test.ts | 22 +++++++++++----
apps/web/src/main.tsx | 59 ++++++++++++++++++++-------------------
2 files changed, 46 insertions(+), 35 deletions(-)
diff --git a/apps/web/src/main.test.ts b/apps/web/src/main.test.ts
index d4790542f1670..1200ff6afab58 100644
--- a/apps/web/src/main.test.ts
+++ b/apps/web/src/main.test.ts
@@ -8,7 +8,7 @@ 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 bootMain(
{ sessionStorage = new Map(), anyHover = true },
- interact: (page: EventTarget) => void,
+ interact: (page: EventTarget, setAnyHover: (matches: boolean) => void) => void,
) {
vi.resetModules();
const reload = vi.fn().mockName("location.reload");
@@ -20,10 +20,17 @@ async function bootMain(
},
location: { reload },
matchMedia: (query: string) => ({
- matches: anyHover && query.endsWith("hover: hover)"),
- addEventListener: () => {},
+ get matches() {
+ return anyHover && query.endsWith("hover: hover)");
+ },
+ addEventListener: (type: string, listener: () => void) =>
+ page.addEventListener(type, listener),
}),
});
+ const setAnyHover = (matches: boolean) => {
+ anyHover = matches;
+ page.dispatchEvent(new Event("change"));
+ };
const root = {
attributes: new Set(),
toggleAttribute: (name: string, force: boolean) =>
@@ -34,7 +41,7 @@ async function bootMain(
try {
const { boot } = await import("./bootstrap");
await boot;
- interact(page);
+ interact(page, setAnyHover);
return { reload, root };
} finally {
vi.unstubAllGlobals();
@@ -62,13 +69,16 @@ it.each([
marked: false,
},
{ anyHover: true, input: "pointermove:touch", marked: true },
+ { anyHover: true, input: "pointermove:touch any-hover:none pointermove:mouse", marked: true },
+ { anyHover: true, input: "pointermove:mouse any-hover:none pointermove:touch", marked: false },
])(
"hover markers are $marked with any-hover $anyHover after $input",
async ({ anyHover, input, marked }) => {
- const { root } = await bootMain({ anyHover }, (page) => {
+ const { root } = await bootMain({ anyHover }, (page, setAnyHover) => {
for (const event of input.split(" ")) {
const [type = "", pointerType] = event.split(":");
- page.dispatchEvent(Object.assign(new Event(type), { pointerType }));
+ if (type === "any-hover") setAnyHover(false);
+ else page.dispatchEvent(Object.assign(new Event(type), { pointerType }));
}
});
diff --git a/apps/web/src/main.tsx b/apps/web/src/main.tsx
index a6b3a1fbf1a9a..c0b7c97a5c8eb 100644
--- a/apps/web/src/main.tsx
+++ b/apps/web/src/main.tsx
@@ -4,6 +4,7 @@ import ReactDOM from "react-dom/client";
import "@fontsource-variable/inter";
import "./index.css";
+import { trackKeyboardLayout } from "./keyboardLayout";
import { hasCloudPublicConfig } from "./cloud/publicConfig";
import { isElectron } from "./env";
import { startAppServices } from "./appInit";
@@ -11,6 +12,9 @@ import { AppRoot } from "./AppRoot";
import { whenLocaleReady } from "./i18n/runtime";
import { chunkLoadState } from "./lib/chunkReloadGuard";
+const stopTrackingKeyboardLayout = trackKeyboardLayout();
+import.meta.hot?.dispose(stopTrackingKeyboardLayout);
+
const router = startAppServices();
const clerkPublishableKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string | undefined;
@@ -18,40 +22,37 @@ const clerkPublishableKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY as string
// index.css gates hover variants on these markers instead of media queries, so a VDI/VM mouse that
// Chromium reports as non-hovering can set them too.
const root = document.documentElement;
-const hoverMarkers = [
- ["data-hover", window.matchMedia("(hover: hover)")],
- ["data-any-hover", window.matchMedia("(any-hover: hover)")],
-] as const;
+const hoverQuery = window.matchMedia("(hover: hover)");
+const anyHoverQuery = window.matchMedia("(any-hover: hover)");
let lastPointerIsMouse = false;
const syncHoverMarkers = () => {
- for (const [name, query] of hoverMarkers) {
- root.toggleAttribute(name, query.matches || lastPointerIsMouse);
- }
+ const mouseFallback = lastPointerIsMouse && !anyHoverQuery.matches;
+ root.toggleAttribute("data-hover", hoverQuery.matches || mouseFallback);
+ root.toggleAttribute("data-any-hover", anyHoverQuery.matches || mouseFallback);
};
-for (const [, query] of hoverMarkers) query.addEventListener("change", syncHoverMarkers);
+hoverQuery.addEventListener("change", syncHoverMarkers);
+anyHoverQuery.addEventListener("change", syncHoverMarkers);
syncHoverMarkers();
-if (!hoverMarkers[1][1].matches) {
- const setLastPointer = (isMouse: boolean) => {
- if (isMouse === lastPointerIsMouse) return;
- lastPointerIsMouse = isMouse;
- syncHoverMarkers();
- };
- // Capture phase: a handler that stops propagation must not hide the pointer type.
- const options = { capture: true, passive: true };
- window.addEventListener(
- "pointermove",
- (event) => setLastPointer(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" && setLastPointer(false),
- options,
- );
-}
+const setLastPointer = (isMouse: boolean) => {
+ if (isMouse === lastPointerIsMouse) return;
+ lastPointerIsMouse = isMouse;
+ syncHoverMarkers();
+};
+// Capture phase: a handler that stops propagation must not hide the pointer type.
+const pointerOptions = { capture: true, passive: true };
+window.addEventListener(
+ "pointermove",
+ (event) => setLastPointer(event.pointerType === "mouse"),
+ pointerOptions,
+);
+// 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" && setLastPointer(false),
+ pointerOptions,
+);
const app = ;