Skip to content

Conversation

@ryanking13
Copy link
Member

@ryanking13 ryanking13 commented Jun 11, 2025

Description

Hopefully resolve #5670

Checklist

@ryanking13
Copy link
Member Author

@WebReflection

Could you check if this patch works? I deployed it in the GH pages.

https://ryanking13.github.io/temp-pyodide-nightly-runtime/console.html

+ // AND if the device has multi-touch capabilities (navigator.maxTouchPoints > 1)
+ let isIOS = globalThis.navigator && (
+ /iPad|iPhone|iPod/.test(navigator.userAgent) ||
+ (navigator.platform === 'MacIntel' && typeof navigator.maxTouchPoints !== 'undefined' && navigator.maxTouchPoints > 1)
Copy link
Contributor

@WebReflection WebReflection Jun 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI undefined > 1 is always false so that a check for a type as undefined is bloat but, most importantly, a check that access the property might have side-effects ... it's a long story but if you really want to check the existence, you are better off with 'maxTouchPoints' in navigator instead of typeof navigator.maxTouchPoints as in operator signals the presence of either accessors or values but it doesn't reach these (lazy accessors can backfire, I have learned this long time ago)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think comparing typeof something to "undefined" should only be done for a top level name because x === undefined raises an error in strict mode. But a.b === undefined does not. They are distinct checks since if you set a.b = undefined then "b" in a is true.

But this check only happens once on startup so it's not all that important exactly how it happens as long as it filters out all the iDevices.

Copy link
Contributor

@WebReflection WebReflection Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact in produces true but the value is undefined won't invalidate what I've said because undefined > 1 is always false but, logically speaking, the check should be typeof navigator.maxTouchPoints === 'number' && navigator.maxTouchPoints > 1 if we want to be sure that typeof has a reason to exist at all in there ... anyway, it's a nit but the current check is both redundant and not clean in its intent ... glad it shipped though 🥳

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the heads up @WebReflection! Since upstream PR is merged as-is (that was fast 🙄), I would like to merge this as-is to prevent future conflict. This patch is a hack anyways, so let's drop it when Apple delivers a fix.

@WebReflection
Copy link
Contributor

@ryanking13 nit a part, it works like a charm:

image

@ryanking13 ryanking13 merged commit f4c7eba into pyodide:main Jun 12, 2025
7 of 9 checks passed
@ryanking13 ryanking13 deleted the ipad-patch branch June 12, 2025 08:34
@hoodmane
Copy link
Member

Thanks @ryanking13 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iPad on OS 18 harakiri in 0.27.1 (not 0.27.0)

3 participants