cheogram-www
created pr with
cheogram-www/hover-fix.1
cmds
checkout latest patchset:
ssh pr.pico.sh pull cheogram-www:hover-fix | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull cheogram-www:hover-fix [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh cheogram-www:hover-fixadd comment to patch request:
ssh pr.pico.sh comment cheogram-www:hover-fix "lgtm!"
Patchset
cheogram-www/hover-fix.1
Fix MUI hover on touchscreen laptops
Eric Roberts
2026-11-27T21:21:42ZMUI'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
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)
+5
-2
src/index.tsx
#
| ... | ... | @@ -19,6 +20,7 @@ import { NuqsAdapter } from "nuqs/adapters/react-router/v7"; | |
| 19 | 20 | import { SearchMessages } from "./components/SearchMessages"; | |
| 20 | 21 | import { Settings } from "./components/Settings"; | |
| 21 | 22 | import { ThemeProvider as MuiThemeProvider, createTheme } from "@mui/material"; | |
| 23 | + | import { muiStyleCache } from "./muiStyleCache"; | |
| 22 | 24 | import * as libsignal from "@privacyresearch/libsignal-protocol-typescript"; | |
| 23 | 25 | import "./ext"; | |
| 24 | 26 | import "~build/console"; |
| ... | ... | @@ -69,7 +71,7 @@ const overlayTitlebar = isTauri() && navigator.platform.startsWith("Mac"); | |
| 69 | 71 | const rootElement = document.getElementById("root")!; | |
| 70 | 72 | rootElement.classList.toggle("tauri-overlay", overlayTitlebar); | |
| 71 | 73 | const root = ReactDOM.createRoot(rootElement); | |
| 72 | - | root.render( | |
| 74 | + | const app = ( | |
| 73 | 75 | <StrictMode> | |
| 74 | 76 | {overlayTitlebar && ( | |
| 75 | 77 | <div className="tauri-titlebar" data-tauri-drag-region /> |
| ... | ... | @@ -120,8 +122,9 @@ root.render( | |
| 120 | 122 | </BrowserRouter> | |
| 121 | 123 | </NuqsAdapter> | |
| 122 | 124 | </MuiThemeProvider> | |
| 123 | - | </StrictMode>, | |
| 125 | + | </StrictMode> | |
| 124 | 126 | ); | |
| 127 | + | root.render(<CacheProvider value={muiStyleCache}>{app}</CacheProvider>); | |
| 125 | 128 | ||
| 126 | 129 | if (serviceWorker) { | |
| 127 | 130 | 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 | + | }); |