@tanstack/hotkeys
Version:
Type-safe, framework-agnostic keyboard hotkey management for the browser
20 lines (19 loc) • 851 B
JavaScript
// src/_server.ts
const SERVER_AGENT = /^(?:Node\.js\/|Deno\/|Bun\/|Cloudflare-Workers)/;
/** Whether this runs on a server: no `navigator`, or a server runtime's. */
function isServerRuntime() {
return typeof navigator === "undefined" || SERVER_AGENT.test(String(navigator.userAgent));
}
let warned = false;
/**
* Warns once, in development, when a label's platform is detected during
* server rendering. The server then renders 'linux' labels, which differ for
* users on macOS and Windows after hydration.
*/
function warnServerPlatform() {
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production" && !warned && isServerRuntime()) {
warned = true;
console.warn("[hotkeys] Server-rendered label uses 'linux'. Set the provider's platform with detectPlatform(userAgent)");
}
}
export { isServerRuntime, warnServerPlatform };