From 35243a30e4769d5b6435cdc2fc757afe3e2f7544 Mon Sep 17 00:00:00 2001 From: Angus Hollands Date: Tue, 17 Sep 2024 16:46:18 +0100 Subject: [PATCH] fix: show CMD on mac --- .../site/src/components/Navigation/Search.tsx | 86 ++++++++++++++++--- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/packages/site/src/components/Navigation/Search.tsx b/packages/site/src/components/Navigation/Search.tsx index 59d73df2..eb9bad87 100644 --- a/packages/site/src/components/Navigation/Search.tsx +++ b/packages/site/src/components/Navigation/Search.tsx @@ -134,6 +134,76 @@ function SearchItem({ result }: { result: RankedSearchResult }) { ); } +/** + * Return true if the client is a Mac, false if not, or undefined if running on the server + */ +function isMac(): boolean | undefined { + if (typeof window === 'undefined') { + return undefined; + } else { + console.log({ window }); + const hostIsMac = /mac/i.test( + (window.navigator as any).userAgentData?.platform ?? window.navigator.userAgent, + ); + return hostIsMac; + } +} + +// Blocking code to ensure that the pre-hydration state on the client matches the post-hydration state +// The server with SSR cannot determine the client platform +const clientThemeCode = ` +;(() => { +const script = document.currentScript; +const root = script.parentElement; + +const isMac = /mac/i.test( + window.navigator.userAgentData?.platform ?? window.navigator.userAgent, + ); +root.querySelectorAll(".hide-mac").forEach(node => {node.classList.add(isMac ? "hidden" : "block")}); +root.querySelectorAll(".show-mac").forEach(node => {node.classList.add(!isMac ? "hidden" : "block")}); +})()`; + +function BlockingPlatformLoader() { + return