Skip to content

[Bug] Empty userAgentData.platform is treated as non-Apple, so mod hotkeys and Kbd show Ctrl on macOS #5253

Closed

Description

@Astro-Han

Description

isApplePlatform() in packages/core/src/hooks/useHotkeys.ts and the matching detection in packages/core/src/Kbd/Kbd.tsx commit to userAgentData and can never fall through:

const uaData = 'userAgentData' in navigator ? navigator.userAgentData : null;
if (uaData && typeof uaData === 'object' && 'platform' in uaData) {
  return /mac/i.test(uaData.platform ?? '');   // '' → false, fallback unreachable
}
return /Mac|iPhone|iPad|iPod/.test(navigator.platform ?? '');

When userAgentData.platform is present but empty, the 'platform' in uaData guard passes, /mac/i.test('') is false, and the navigator.platform branch — which would answer correctly — is never reached. An empty string is being read as a negative answer rather than as no answer.

Electron builds that rewrite the app's user-agent / client-hints identity ship exactly that: platform: ''. On macOS the result is that every mod combo registered through useHotkeys listens for Ctrl instead of Cmd, and every <Kbd> renders Ctrl.

Both surfaces are wrong and consistent with each other, so nothing looks broken — the shortcut simply never fires, and the hint tells you to press the key that also doesn't work.

The two call sites are independent copies of the same logic, and the useHotkeys docstring states it "Mirrors the detection used by Kbd so displayed and handled shortcuts agree", so they need the same change.

Suggested direction: treat a blank platform as unknown and fall through to the existing navigator.platform branch, instead of as not Apple. We have this running locally as a patch and are happy to open a PR — but since it touches packages/core/ and changes behavior, tell us whether you want it through the specification protocol first.

Diagnosis and draft prepared with Claude Code; reviewed and verified by the contributor before filing.

Reproduction

In any context where UA-CH is present but blank:

Object.defineProperty(navigator, 'userAgentData', { value: { platform: '' } });
// isApplePlatform() === false, on macOS

End to end: run an Electron build on macOS with an overridden user agent, register useHotkeys('mod+k', fn) and render <Kbd keys="mod+k" />. Cmd+K does not fire and the Kbd shows Ctrl. The same code in Safari/Chrome on the same machine behaves correctly.

Astryx Version

0.4.5 (verified against the published tarball; also present in 0.4.0)

Environment

macOS, Electron / Chromium, any build that overrides the user-agent or client-hints identity.

Activity

  1. HelloOjasMutreja commented on Aug 21, 2026

    @HelloOjasMutreja
    Contributor

    Verified against current main: both isApplePlatform() in useHotkeys.ts (line 84-88) and the matching detection in Kbd.tsx (line 135-140) have the identical structure you describe. 'platform' in uaData is true whenever the key exists at all, blank or not, so an Electron build shipping platform: '' commits to the UA-CH branch, tests /mac/i.test('') (always false), and never reaches the navigator.platform fallback that would answer correctly. Confirmed on both call sites, matching the docstring's claim that they're kept in sync.

    Since you already have a patch running locally, I'll leave the PR to you rather than duplicate the work, happy to review once it's up. Your suggested direction (blank platform treated as unknown, fall through to navigator.platform) matches the actual bug precisely; the one thing I'd flag for the PR itself is keeping both call sites' fix in the same commit given they're documented as needing to stay identical.

  2. added 2 commits that reference this issue on Aug 22, 2026
    a2b4e91
    571499c
  3. added a commit that references this issue on Aug 23, 2026
    b7fc8b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions