Skip to content

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

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.

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