-
Notifications
You must be signed in to change notification settings - Fork 142
fix Cmd Issue #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix Cmd Issue #246
Conversation
Signed-off-by: Gagan202005 <gagansinghal2005@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #3439 by implementing runtime OS detection to display the appropriate keyboard shortcut hint ("Cmd + K" on macOS, "Ctrl + K" on other platforms) in the search button of the navigation bar.
Key Changes:
- Created a new utility hook
ShortcutHintto detect the user's operating system and return the appropriate keyboard shortcut text - Updated the search button in
FloatingNavbarClientto use the new utility instead of hardcoded "Ctrl + K"
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| utils/GetShortCutHint.ts | New utility hook that detects macOS via user agent and returns the appropriate keyboard shortcut string |
| components/navbar/FloatingNavbarClient.tsx | Imports and uses the new ShortcutHint hook to dynamically display the correct keyboard shortcut |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import { useEffect,useState } from "react"; | ||
| export function ShortcutHint() { | ||
| const [shortcut, setShortcut] = useState("Ctrl + K"); | ||
|
|
||
| useEffect(() => { | ||
| const ua = navigator.userAgent.toLowerCase(); | ||
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | ||
| setShortcut("Cmd + K"); | ||
| } | ||
| }, []); | ||
|
|
||
| return shortcut; | ||
| } |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a React hook (with useState and useEffect) for this functionality is unnecessarily complex and causes performance overhead. Since the OS doesn't change during the user's session, this could be simplified to a pure function that returns the shortcut string directly, or use useMemo to cache the result. The current implementation causes unnecessary re-renders of the component.
| import { useEffect,useState } from "react"; | |
| export function ShortcutHint() { | |
| const [shortcut, setShortcut] = useState("Ctrl + K"); | |
| useEffect(() => { | |
| const ua = navigator.userAgent.toLowerCase(); | |
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | |
| setShortcut("Cmd + K"); | |
| } | |
| }, []); | |
| return shortcut; | |
| } | |
| export function ShortcutHint() { | |
| const ua = | |
| typeof navigator !== "undefined" | |
| ? navigator.userAgent.toLowerCase() | |
| : ""; | |
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | |
| return "Cmd + K"; | |
| } | |
| return "Ctrl + K"; | |
| } |
| @@ -0,0 +1,13 @@ | |||
| import { useEffect,useState } from "react"; | |||
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after comma in the import statement. Should be "useEffect, useState" instead of "useEffect,useState".
| import { useEffect,useState } from "react"; | |
| import { useEffect, useState } from "react"; |
| @@ -0,0 +1,13 @@ | |||
| import { useEffect,useState } from "react"; | |||
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file naming convention is inconsistent with other utils. This file uses PascalCase "GetShortCutHint.ts", while other utility files in this directory follow camelCase naming (e.g., "calculateReadingTime.ts", "sanitizeAuthorSlug.ts"). Consider renaming to "getShortcutHint.ts" for consistency.
| import { useEffect,useState } from "react"; | ||
| export function ShortcutHint() { | ||
| const [shortcut, setShortcut] = useState("Ctrl + K"); | ||
|
|
||
| useEffect(() => { | ||
| const ua = navigator.userAgent.toLowerCase(); | ||
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | ||
| setShortcut("Cmd + K"); | ||
| } | ||
| }, []); | ||
|
|
||
| return shortcut; |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation will cause a hydration mismatch in Next.js. The component initially renders "Ctrl + K" during SSR/first render, then updates to "Cmd + K" on macOS after the useEffect runs. This creates a flash of incorrect content and triggers React hydration warnings. Since this component is used in a client component (indicated by "use client" directive), consider using a pure function that detects the OS synchronously during render, or use the same detection method already present in the parent component (line 38 uses navigator.platform).
| import { useEffect,useState } from "react"; | |
| export function ShortcutHint() { | |
| const [shortcut, setShortcut] = useState("Ctrl + K"); | |
| useEffect(() => { | |
| const ua = navigator.userAgent.toLowerCase(); | |
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | |
| setShortcut("Cmd + K"); | |
| } | |
| }, []); | |
| return shortcut; | |
| export function ShortcutHint() { | |
| if (typeof navigator !== "undefined") { | |
| const ua = navigator.userAgent.toLowerCase(); | |
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | |
| return "Cmd + K"; | |
| } | |
| } | |
| return "Ctrl + K"; |
| const ua = navigator.userAgent.toLowerCase(); | ||
| if (ua.includes("macintosh") || ua.includes("mac os x")) { |
Copilot
AI
Jan 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OS detection methods are inconsistent within the same component. This new utility uses "navigator.userAgent" to detect macOS, while the existing keyboard event handler (line 38) uses "navigator.platform". Consider using the same detection method for consistency. Additionally, "navigator.platform" is more reliable for this use case as it's specifically designed for platform detection, whereas "navigator.userAgent" can be modified or spoofed more easily.
| const ua = navigator.userAgent.toLowerCase(); | |
| if (ua.includes("macintosh") || ua.includes("mac os x")) { | |
| const platform = navigator.platform || ""; | |
| if (platform.toUpperCase().includes("MAC")) { |
Related Tickets & Documents
Fixes: keploy/keploy#3439
Description
Type of Change
Testing
Demo
Checklist