Skip to content

Commit 9342f88

Browse files
authored
Fix: "navigator is not defined" on dev env startup (#1933)
1 parent 1e7d378 commit 9342f88

File tree

5 files changed

+25
-16
lines changed

5 files changed

+25
-16
lines changed

apps/mail/components/mail/mail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { Check, ChevronDown, RefreshCcw } from 'lucide-react';
1616
import { useMediaQuery } from '../../hooks/use-media-query';
1717
import useSearchLabels from '@/hooks/use-labels-search';
1818
import * as CustomIcons from '@/components/icons/icons';
19-
import { isMac } from '@/lib/hotkeys/use-hotkey-utils';
2019
import { MailList } from '@/components/mail/mail-list';
2120
import { useNavigate, useParams } from 'react-router';
2221
import { useMail } from '@/components/mail/use-mail';
@@ -31,6 +30,7 @@ import { useIsMobile } from '@/hooks/use-mobile';
3130
import { Button } from '@/components/ui/button';
3231
import { useSession } from '@/lib/auth-client';
3332
import { m } from '@/paraglide/messages';
33+
import { isMac } from '@/lib/platform';
3434
import { useQueryState } from 'nuqs';
3535
import { cn } from '@/lib/utils';
3636
import { useAtom } from 'jotai';

apps/mail/config/shortcuts.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { z } from 'zod';
21
import { keyboardLayoutMapper } from '../utils/keyboard-layout-map';
32
import { getKeyCodeFromKey } from '../utils/keyboard-utils';
3+
import { isMac } from '@/lib/platform';
4+
import { z } from 'zod';
45

56
export const shortcutSchema = z.object({
67
keys: z.array(z.string()),
@@ -28,19 +29,19 @@ export interface EnhancedShortcut extends Shortcut {
2829
*/
2930
export function getDisplayKeysForShortcut(shortcut: Shortcut): string[] {
3031
const detectedLayout = keyboardLayoutMapper.getDetectedLayout();
31-
32-
return shortcut.keys.map(key => {
32+
33+
return shortcut.keys.map((key) => {
3334
// Handle special modifiers first
3435
switch (key.toLowerCase()) {
3536
case 'mod':
36-
return navigator.platform.includes('Mac') ? '⌘' : 'Ctrl';
37+
return isMac ? '⌘' : 'Ctrl';
3738
case 'meta':
3839
return '⌘';
3940
case 'ctrl':
4041
case 'control':
4142
return 'Ctrl';
4243
case 'alt':
43-
return navigator.platform.includes('Mac') ? '⌥' : 'Alt';
44+
return isMac ? '⌥' : 'Alt';
4445
case 'shift':
4546
return '⇧';
4647
case 'escape':
@@ -67,12 +68,11 @@ export function getDisplayKeysForShortcut(shortcut: Shortcut): string[] {
6768
* Convert a key string to its corresponding KeyCode
6869
*/
6970

70-
7171
/**
7272
* Enhance shortcuts with keyboard layout mapping
7373
*/
7474
export function enhanceShortcutsWithMapping(shortcuts: Shortcut[]): EnhancedShortcut[] {
75-
return shortcuts.map(shortcut => ({
75+
return shortcuts.map((shortcut) => ({
7676
...shortcut,
7777
displayKeys: getDisplayKeysForShortcut(shortcut),
7878
mappedKeys: keyboardLayoutMapper.mapKeys(shortcut.keys.map(getKeyCodeFromKey)),
@@ -433,4 +433,5 @@ export const keyboardShortcuts: Shortcut[] = [
433433
/**
434434
* Enhanced keyboard shortcuts with layout mapping
435435
*/
436-
export const enhancedKeyboardShortcuts: EnhancedShortcut[] = enhanceShortcutsWithMapping(keyboardShortcuts);
436+
export const enhancedKeyboardShortcuts: EnhancedShortcut[] =
437+
enhanceShortcutsWithMapping(keyboardShortcuts);

apps/mail/lib/hotkeys/use-hotkey-utils.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { keyboardLayoutMapper, type KeyboardLayout } from '@/utils/keyboard-layo
44
import { getKeyCodeFromKey } from '@/utils/keyboard-utils';
55
import { useHotkeys } from 'react-hotkeys-hook';
66
import { useCallback, useMemo } from 'react';
7+
import { isMac } from '@/lib/platform';
78

89
export const useShortcutCache = () => {
910
// const { data: shortcuts, mutate } = useSWR<Shortcut[]>(
@@ -49,11 +50,6 @@ export const useShortcutCache = () => {
4950
};
5051
};
5152

52-
export const isMac =
53-
typeof window !== 'undefined' &&
54-
(/macintosh|mac os x/i.test(navigator.userAgent) ||
55-
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1));
56-
5753
const dvorakToQwerty: Record<string, string> = {
5854
a: 'a',
5955
b: 'x',

apps/mail/lib/platform.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const isMac =
2+
typeof window !== 'undefined' &&
3+
typeof navigator !== 'undefined' &&
4+
(/macintosh|mac os x/i.test(navigator.userAgent) ||
5+
(navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1));

pnpm-workspace.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ packages:
22
- apps/*
33
- packages/*
44
- scripts/*
5+
56
catalog:
67
zod: ^3.25.42
78
better-auth: ^1.3.4
@@ -15,14 +16,20 @@ catalog:
1516
drizzle-orm: ^0.43.1
1617
drizzle-kit: ^0.31.1
1718
'@types/node': ^22.15.21
18-
'react': ^19.1.0
19-
'react-dom': ^19.1.0
19+
react: ^19.1.0
20+
react-dom: ^19.1.0
21+
2022
onlyBuiltDependencies:
23+
- '@sentry/cli'
24+
- '@tailwindcss/oxide'
25+
- better-sqlite3
2126
- core-js
2227
- core-js-pure
2328
- esbuild
29+
- msw
2430
- sharp
2531
- unrs-resolver
2632
- workerd
33+
2734
patchedDependencies:
2835
novel: patches/novel.patch

0 commit comments

Comments
 (0)