-
Notifications
You must be signed in to change notification settings - Fork 1
fix: prevent mobile/iPad crash β Lenis RAF leak, canvas DPR, particle overload #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,4 +8,11 @@ const debouncedHandler = (callback: () => void, period: number) => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default debouncedHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default debouncedHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Returns true when the device is a touch-primary device (phone/tablet). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Evaluated once per call β callers should cache the result where needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const isTouchDevice = (): boolean => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| window.matchMedia("(hover: none) and (pointer: coarse)").matches; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+18
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const isTouchDevice = (): boolean => | |
| window.matchMedia("(hover: none) and (pointer: coarse)").matches; | |
| export const isTouchDevice = (): boolean => { | |
| // Guard against non-browser environments (SSR, some test runners) | |
| if (typeof window === "undefined") { | |
| return false; | |
| } | |
| // Prefer navigator.maxTouchPoints when available | |
| if (typeof navigator !== "undefined" && typeof navigator.maxTouchPoints === "number") { | |
| if (navigator.maxTouchPoints > 0) { | |
| return true; | |
| } | |
| } | |
| // Fallback to matchMedia when supported | |
| if (typeof window.matchMedia === "function") { | |
| try { | |
| return window.matchMedia("(hover: none) and (pointer: coarse)").matches; | |
| } catch { | |
| // If matchMedia throws for any reason, fall through to default | |
| } | |
| } | |
| // Conservative default when we cannot reliably detect touch capability | |
| return false; | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DPR cap uses
window.innerWidth < 768to decide βmobileβ, which excludes many iPads/tablets (often >= 768px wide). If the goal is to reduce canvas GPU memory on iPad too, consider basing the DPR cap onisTouchDevice()(or a max pixel budget) instead of only viewport width so tablets donβt still allocate at DPR 2.