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
20 changes: 19 additions & 1 deletion apps/web/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 46 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 the entry 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,59 @@ 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 = {
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<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, 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);
},
);
19 changes: 19 additions & 0 deletions apps/web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <AppRoot router={router} />;

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