Skip to content

Commit

Permalink
Make localizeMod SSR safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Cbodfield authored May 6, 2024
1 parent a2e0df9 commit e9dbc5b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/hotkey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export function normalizeHotkey(hotkey: string, platform?: string | undefined):

const matchApplePlatform = /Mac|iPod|iPhone|iPad/i

function localizeMod(hotkey: string, platform: string = navigator.platform): string {
function localizeMod(hotkey: string, platform?: string): string {
const ssrSafeWindow = typeof window === "undefined" ? undefined : window
const safePlatform = ssrSafeWindow
? ssrSafeWindow.navigator.platform
: platform

const localModifier = matchApplePlatform.test(platform) ? 'Meta' : 'Control'
return hotkey.replace('Mod', localModifier)
}
Expand Down

0 comments on commit e9dbc5b

Please sign in to comment.