cheogram-www

created pr with cheogram-www/hover-fix.1 on 2026-11-27T21:32:25Z · by 3c31bc8c
cmds
checkout latest patchset:
ssh pr.pico.sh pull cheogram-www:hover-fix | git am -3
checkout specific patchset revision:
ssh pr.pico.sh pull cheogram-www:hover-fix [rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh cheogram-www:hover-fix
add comment to patch request:
ssh pr.pico.sh comment cheogram-www:hover-fix "lgtm!"

Patchset cheogram-www/hover-fix.1 on 2026-11-27T21:32:25Z · commit 7b679ab

Fix MUI hover on touchscreen laptops
Eric Roberts 2026-11-27T21:21:42Z
MUI's CSS is using `@media (hover: hover)` which can mean on devices
that have multiple inputs (touchscreen and mouse) it can not apply hover
styles if the touchscreen is considered the primary input.

We can fix this by changing the media query to `@media (any-hover:
hover)`. We could have narrowly applied this fix to the places we know
have an issue, but I think there's not a good reason for us we would
want hover: hover instead of any-hover: hover, so I'm making sure it
doesn't show up in the MUI CSS.

We already had emotion and stylis as dependencies of MUI. Using a custom
cache as per MUI docs[^1] and a stylis custom rule[^2] to rewrite hover
to any-hover.

I confirmed it fixed it by setting my Firefox to have a primary input of
touchscreen and testing before and after.

[^1]: https://mui.com/material-ui/integrations/interoperability/#css-injection-order
[^2]: https://emotion.sh/docs/@emotion/cache#stylisplugins
Diff stat
package.json | 3 +++
src/index.tsx | 7 +++++--
src/muiStyleCache.test.tsx | 22 ++++++++++++++++++++++
src/muiStyleCache.ts | 18 ++++++++++++++++++
4 files changed, 48 insertions(+), 2 deletions(-)
Semantic diff summary
0 added, 0 modified, 0 signature changed, 0 removed across 3 analyzed files (1 file skipped: unsupported file type)
+3 -0 package.json #
......@@ -10,6 +10,7 @@
1010 "@dnd-kit/sortable": "^10.0.0",
1111 "@emoji-mart/data": "^1.1.2",
1212 "@emoji-mart/react": "^1.1.1",
13+ "@emotion/cache": "^11.14.0",
1314 "@emotion/react": "^11.14.0",
1415 "@emotion/styled": "^11.14.1",
1516 "@fortawesome/fontawesome-svg-core": "^6.6.0",
......@@ -47,6 +48,7 @@
4748 "react-router": "^7.9.3",
4849 "react-virtuoso": "^4.18.6",
4950 "sasl-scram-sha-1": "^1.3.0",
51+ "stylis": "4.2.0",
5052 "unsplash-react": "^0.3.1",
5153 "uuidv7": "^0.6.3",
5254 "visual-dom-diff": "^0.7.3",
......@@ -89,6 +91,7 @@
8991 "@sentry/cli": "^3.4.2",
9092 "@tauri-apps/cli": "^2.12.3",
9193 "@testing-library/react": "16.3.0",
94+ "@types/stylis": "^4.2.7",
9295 "@vitejs/plugin-react": "^6.3.0",
9396 "eslint": "^9.37.0",
9497 "eslint-plugin-react": "^7.37.5",
+5 -2 src/index.tsx #
......@@ -1,4 +1,5 @@
11 import { StrictMode } from "react";
2+import { CacheProvider } from "@emotion/react";
23 import { isTauri } from "@tauri-apps/api/core";
34 import { readyServiceWorker, serviceWorker } from "./util";
45 import ReactDOM from "react-dom/client";
......@@ -19,6 +20,7 @@ import { NuqsAdapter } from "nuqs/adapters/react-router/v7";
1920 import { SearchMessages } from "./components/SearchMessages";
2021 import { Settings } from "./components/Settings";
2122 import { ThemeProvider as MuiThemeProvider, createTheme } from "@mui/material";
23+import { muiStyleCache } from "./muiStyleCache";
2224 import * as libsignal from "@privacyresearch/libsignal-protocol-typescript";
2325 import "./ext";
2426 import "~build/console";
......@@ -69,7 +71,7 @@ const overlayTitlebar = isTauri() && navigator.platform.startsWith("Mac");
6971 const rootElement = document.getElementById("root")!;
7072 rootElement.classList.toggle("tauri-overlay", overlayTitlebar);
7173 const root = ReactDOM.createRoot(rootElement);
72-root.render(
74+const app = (
7375 <StrictMode>
7476 {overlayTitlebar && (
7577 <div className="tauri-titlebar" data-tauri-drag-region />
......@@ -120,8 +122,9 @@ root.render(
120122 </BrowserRouter>
121123 </NuqsAdapter>
122124 </MuiThemeProvider>
123- </StrictMode>,
125+ </StrictMode>
124126 );
127+root.render(<CacheProvider value={muiStyleCache}>{app}</CacheProvider>);
125128
126129 if (serviceWorker) {
127130 if (import.meta.env.PROD) serviceWorker.register("/sw.js", { scope: "/" });
+22 -0 src/muiStyleCache.test.tsx #
......@@ -0,0 +1,22 @@
1+// @vitest-environment jsdom
2+
3+import { CacheProvider } from "@emotion/react";
4+import { ListItemButton } from "@mui/material";
5+import { cleanup, render } from "@testing-library/react";
6+import { afterEach, expect, it } from "vitest";
7+import { muiStyleCache } from "./muiStyleCache";
8+
9+afterEach(cleanup);
10+
11+it("emits MUI hover resets only when no pointing device can hover", () => {
12+ render(
13+ <CacheProvider value={muiStyleCache}>
14+ <ListItemButton selected>Search result</ListItemButton>
15+ </CacheProvider>,
16+ );
17+ const css = Array.from(document.styleSheets)
18+ .flatMap((sheet) => Array.from(sheet.cssRules, (rule) => rule.cssText))
19+ .join("\n");
20+ expect(css).toMatch(/@media\s*\(any-hover:\s*none\).*:hover/s);
21+ expect(css).not.toMatch(/@media\s*\(hover:\s*none\)/);
22+});
+18 -0 src/muiStyleCache.ts #
......@@ -0,0 +1,18 @@
1+import createCache from "@emotion/cache";
2+import { prefixer } from "stylis";
3+
4+export const muiStyleCache = createCache({
5+ key: "mui",
6+ stylisPlugins: [
7+ (rule) => {
8+ if (rule.type === "@media") {
9+ rule.value = rule.value.replace(/\(\s*hover\s*:/g, "(any-hover:");
10+ }
11+ },
12+ // Prefixer is part of the default plugins list. Since we have a custom
13+ // plugin we now need to include it ourselves.
14+ //
15+ // https://emotion.sh/docs/@emotion/cache#stylisplugins
16+ prefixer,
17+ ],
18+});
Back to top