fix(core): a blank client-hints platform is unknown, not non-Apple - #5325
fix(core): a blank client-hints platform is unknown, not non-Apple#5325Astro-Han wants to merge 1 commit into
Conversation
|
Hi @Astro-Han! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
f2165eb to
a2b4e91
Compare
…Apple
`isApplePlatform()` in `useHotkeys` and `detectMac()` in `Kbd` both prefer
`navigator.userAgentData.platform` and fall back to `navigator.platform`.
The guard on that preference was `'platform' in uaData`, true whenever the
key exists at all, blank or not. A build reporting `platform: ''` committed
to the client-hints branch, evaluated `/mac/i.test('')`, and got `false`
without ever reaching the fallback that would have answered correctly. An
empty string was read as "not Apple" rather than as "no answer".
Electron and other embedders that rewrite the app's user-agent or
client-hints identity ship exactly that. On macOS every `mod` combo
registered through `useHotkeys` listened for Ctrl instead of Cmd, and every
`<Kbd>` drew Ctrl. Both surfaces agreed with each other, so nothing looked
broken: the shortcut never fired, and the hint named the key that also did
not work.
A blank platform now falls through to `navigator.platform`. Both call sites
change in this one commit, since the `useHotkeys` docstring states it
mirrors the detection used by `Kbd` so displayed and handled shortcuts
agree.
Fixes facebook#5253
a2b4e91 to
571499c
Compare
Fixes #5253.
The defect
isApplePlatform()inpackages/core/src/hooks/useHotkeys.tsanddetectMac()inpackages/core/src/Kbd/Kbd.tsxare independent copies of the same detection: prefernavigator.userAgentData.platform, fall back tonavigator.platform. The guard on that preference was'platform' in uaDatais true whenever the key exists at all, blank or not, and??only defends againstnull/undefined. So a blank platform takes the client-hints branch, evaluates/mac/i.test(''), returnsfalse, and the fallback that would have answered correctly is never reached. An empty string was read as a negative answer rather than as no answer.Electron and other embedders that rewrite the app's user-agent or client-hints identity ship exactly that. On macOS every
modcombo registered throughuseHotkeyslistened for Ctrl instead of Cmd, and every<Kbd>drew Ctrl. Both surfaces agreed with each other, so nothing looked broken: the shortcut simply never fired, and the hint named the key that also did not work. The same code in Safari or Chrome on the same machine behaved correctly.The fix
A blank (or non-string) platform is treated as unknown and falls through. A client-hints platform that actually names something is still preferred, so nothing changes for browsers that report one.
Both call sites change in one commit: the
useHotkeysdocstring states the hook "Mirrors the detection used by Kbd so displayed and handled shortcuts agree", so fixing one alone would produce the failure this bug is least likely to be noticed in — a shortcut that fires on a key the hint does not name. The shared docstring line is updated in both, kept identical.Tests
One regression test per call site, written in the platform-spoofing style each file already uses (
vi.stubGlobalinuseHotkeys.test.ts,Object.definePropertyinKbd.test.tsx): withuserAgentData.platform: ''andnavigator.platform: 'MacIntel',mod+kfires onmetaKeyand not onctrlKey, and<Kbd keys="mod" />renders ⌘. Both fail onmainand pass with the fix.Kbd.test.tsx'safterEachalso deletes the spoofeduserAgentDataso nothing leaks into the tests that follow.Validation
vitest runon both test files — 31 passed; verified the two new Mac tests fail with the source change revertedpnpm -F @astryxdesign/core typecheck,eslinton the touched files,pnpm check:repo— all cleanA
[fix]changeset is included (@astryxdesign/core: patch).Diagnosis, patch, and this description were prepared with Claude Code; every line was read and verified by me before opening, and the validation above was run locally.