Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
/* 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;
}
}
&:is([data-mouse-hover] *):hover {
@slot;
}
}

/* On mobile, morph the expanded hero composer into the compact docked
Expand Down
37 changes: 31 additions & 6 deletions apps/web/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ vi.mock("./i18n/runtime", () => ({ whenLocaleReady: async () => {} }));
vi.mock("react-dom/client", () => ({ default: { createRoot: () => ({ render: () => {} }) } }));

// Boots main in a fresh page that shares the tab's sessionStorage, as a reload does.
async function bootThenFailLazyChunk(sessionStorage: Map<string, string>) {
async function bootMain(
{ sessionStorage = new Map<string, string>(), anyHover = true },
interact: (page: EventTarget) => void,
) {
vi.resetModules();
const reload = vi.fn().mockName("location.reload");
const page = Object.assign(new EventTarget(), {
Expand All @@ -16,22 +19,44 @@ async function bootThenFailLazyChunk(sessionStorage: Map<string, string>) {
removeItem: (key: string) => sessionStorage.delete(key),
},
location: { reload },
matchMedia: (query: string) => ({ matches: query === "(any-hover: hover)" && anyHover }),
});
const root = { dataset: {} as Record<string, string> };
vi.stubGlobal("window", page);
vi.stubGlobal("document", { getElementById: () => ({}) });
vi.stubGlobal("document", { getElementById: () => ({}), documentElement: root });
try {
const { startup } = await import("./main");
await startup;
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<string, string>();

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, pointerTypes: ["touch", "pen"], marked: false },
{ anyHover: false, pointerTypes: ["touch", "mouse"], marked: true },
{ anyHover: true, pointerTypes: ["mouse"], marked: false },
])(
"marks mouse hover with any-hover $anyHover after $pointerTypes moves",
async ({ anyHover, pointerTypes, marked }) => {
const { root } = await bootMain({ anyHover }, (page) => {
for (const pointerType of pointerTypes) {
page.dispatchEvent(Object.assign(new Event("pointermove"), { pointerType }));
}
});

expect("mouseHover" in root.dataset).toBe(marked);
},
);
10 changes: 10 additions & 0 deletions apps/web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ window.addEventListener("vite:preloadError", (event) => {
}
});

// VDI/VM absolute pointers can report `any-hover: none` while delivering real mouse events.
if (!window.matchMedia("(any-hover: hover)").matches) {
const markMouseHover = (event: PointerEvent) => {
if (event.pointerType !== "mouse") return;
document.documentElement.dataset.mouseHover = "";
window.removeEventListener("pointermove", markMouseHover);
};
window.addEventListener("pointermove", markMouseHover, { passive: true });
}

const app = <AppRoot router={router} />;

// Split by runtime to keep Clerk out of local startup and clerk-js out of browser builds.
Expand Down
Loading