Skip to content

Comments

fix: update device detection logic#55

Merged
ChinmayMhatre merged 1 commit intomainfrom
device-detection-fix
Sep 17, 2025
Merged

fix: update device detection logic#55
ChinmayMhatre merged 1 commit intomainfrom
device-detection-fix

Conversation

@ChinmayMhatre
Copy link
Contributor

@ChinmayMhatre ChinmayMhatre commented Sep 17, 2025

Description

Testing (ignore for documentation update)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist:

Additional Notes:

Summary by CodeRabbit

  • Bug Fixes
    • Improved device-type detection to reduce misclassification, especially on Windows touch laptops and Windows desktops.
    • Refined small-screen handling for more accurate mobile vs. desktop behavior.
    • Adjusted mobile feature detection to better differentiate desktop browsers with touch support.
  • Chores
    • Bumped version to 4.5.1.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link

coderabbitai bot commented Sep 17, 2025

Walkthrough

Version bumped in package.json to 4.5.1. Device detection logic in src/utils/device.ts adjusted: tighter small-screen threshold, added Windows touch laptop exception, added Windows desktop penalty, and refined scoring conditions to handle Windows environments and Desktop Safari exclusions.

Changes

Cohort / File(s) Summary
Version bump
package.json
Incremented version from 4.5.0 to 4.5.1; no other fields changed.
Device detection heuristics
src/utils/device.ts
Tightened small-screen threshold to 480px; added isWindowsTouchLaptop; gated small-screen/mobile-APIs bonuses to exclude Windows touch laptops and Desktop Safari; introduced isWindowsDesktop with desktop penalty; updated scoring paths and comments accordingly.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor App
  participant Detector as DeviceDetector
  participant Env as EnvSignals\n(UA, screen, inputs, APIs)
  participant Scorer as Scoring Heuristics

  App->>Detector: detectDeviceType()
  Detector->>Env: read userAgent, screenWidth/Height, touch/mouse, APIs
  Env-->>Detector: signals

  rect rgb(235, 245, 255)
    note over Detector,Scorer: Compute derived flags
    Detector->>Scorer: hasSmallScreen (<=480), hasMobileAPIs, hasTouch, hasPreciseMouse
    Detector->>Scorer: isDesktopSafari, hasMobileUserAgent
    Detector->>Scorer: isWindowsTouchLaptop, isWindowsDesktop
  end

  rect rgb(240, 255, 240)
    note over Scorer: Score adjustments
    Scorer-->>Detector: +mobileScore for small screen (not WindowsTouchLaptop)
    Scorer-->>Detector: +mobileScore for mobile APIs (not WindowsTouchLaptop, not DesktopSafari)
    Scorer-->>Detector: -mobileScore for WindowsDesktop
  end

  Detector-->>App: classification (mobile/desktop) + flags
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

Possibly related PRs

Suggested reviewers

  • kryptocodes
  • Kushal7788
  • Karam19

Poem

A hop, a skip, a Windows twist—
I sniff the UA, can’t resist!
Small screens shrink to 480’s lane,
Touchy laps dodge mobile’s gain.
Desktops penaltied, scores align—
Version bumps to keep in time.
Thump-thump! The heuristics shine. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: update device detection logic" is concise, uses a clear "fix:" prefix, and accurately summarizes the primary change in the PR (updates to device detection behavior in src/utils/device.ts, including Windows touch laptop and desktop handling), so it conveys the main intent to reviewers scanning history. It is specific enough without needing to list all implementation details.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch device-detection-fix

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

This PR is being reviewed by Cursor Bugbot

Details

Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

Bug: Windows Touch Laptop Detection Flaw

The mobile device detection logic inconsistently applies the isWindowsTouchLaptop exclusion. The 'High DPI with small screen' and 'Viewport meta tag with small screen' conditions still add mobile points to Windows touch laptops, potentially misclassifying them.

src/utils/device.ts#L124-L134

// High DPI with small screen = mobile (+1 point)
const hasHighDPI = window.devicePixelRatio > 1.5;
if (hasHighDPI && hasSmallScreen) {
mobileScore += 1;
}
// Viewport meta tag with small screen = mobile optimized (+1 point)
const hasViewportMeta = safeQuerySelector('meta[name="viewport"]');
if (hasViewportMeta && hasSmallScreen) {
mobileScore += 1;
}

Fix in Cursor Fix in Web


Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
src/utils/device.ts (4)

75-75: Make small-screen check orientation-agnostic.

Using the min dimension keeps the intent while avoiding duplicate comparisons.

-    const hasSmallScreen = screenWidth <= 480 || screenHeight <= 480;
+    const hasSmallScreen = Math.min(screenWidth, screenHeight) <= 480;

85-89: Harden Windows touch‑laptop detection with UA‑CH fallback.

Leverage navigator.userAgentData.platform when available to reduce UA string brittleness.

-    const isWindowsTouchLaptop = /Windows/i.test(userAgent) && 
-                                hasPreciseMouse && 
-                                hasTouch;
+    const isWindowsTouchLaptop =
+        (userAgent.includes('windows') || userAgentData?.platform?.toLowerCase() === 'windows') &&
+        hasPreciseMouse &&
+        hasTouch;

113-121: Mobile‑APIs gating looks safer; minor robustness nit.

Condition reads well and excludes Desktop Safari and Windows touch laptops. If you later adopt UA‑CH, you could also add userAgentData?.mobile === true as a lightweight positive signal (would require extending the local UA‑CH type).


157-162: Windows desktop penalty may overcorrect on Windows tablets.

Unconditionally subtracting 3 for any Windows UA without a mobile UA can misclassify Windows tablets that lack mobile UA tokens. Gate by input features too.

-    const isWindowsDesktop = /Windows/i.test(userAgent) && !hasMobileUserAgent;
-    if (isWindowsDesktop) {
+    const isWindowsDesktop = (userAgent.includes('windows') || userAgentData?.platform?.toLowerCase() === 'windows')
+                             && !hasMobileUserAgent
+                             && !hasTouch
+                             && (hasPreciseMouse || canHover);
+    if (isWindowsDesktop) {
         mobileScore -= 3;
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab5e28d and 0f99598.

📒 Files selected for processing (2)
  • package.json (1 hunks)
  • src/utils/device.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cursor Bugbot
🔇 Additional comments (2)
package.json (1)

3-3: Patch bump looks correct; verify release artifacts.

4.5.1 aligns with a fix-only PR. Please ensure release-it will tag v4.5.1 and publish with the correct changelog entry.

src/utils/device.ts (1)

101-104: Good exception for Windows touch laptops.

This avoids small‑viewport false positives on 2‑in‑1s. Consider adding a unit test with a Surface‑class UA + touch + pointer:fine to lock this in.

@ChinmayMhatre ChinmayMhatre merged commit cf20556 into main Sep 17, 2025
2 checks passed
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.

3 participants