Skip to content

Conversation

VitroidFPV
Copy link
Member

@VitroidFPV VitroidFPV commented Aug 16, 2025

This should address usability issues with Brave and potentially other browsers that focus on user privacy by disabling these APIs

Summary by CodeRabbit

  • Bug Fixes
    • Improved network status display to handle unsupported browsers more gracefully, preventing errors when network information is unavailable.
    • Added safe detection and fallback values for connection type, downlink, and RTT, showing “Unknown” when data is missing.
    • Ensured UI consistently displays network metrics (type, Mbps, ms) only when available, enhancing reliability and clarity.

Copy link
Contributor

coderabbitai bot commented Aug 16, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Alias navigator.connection and use optional chaining with default fallbacks for effectiveType, downlink, and rtt; update showNetworkStatus to read from the alias and render the fallback/formatted values. Decision logic (offline/slow/online) is unchanged. Note: a likely typo uses an undefined downLink variable in UI update.

Changes

Cohort / File(s) Summary
Network info safe access and UI binding updates
src/js/tabs/setup.js
Create const connection = navigator.connection; replace direct reads with `connection?.effectiveType

Sequence Diagram(s)

sequenceDiagram
    participant Browser
    participant setup.js
    participant UI

    Note over Browser,setup.js #E8F1FF: read network info (safe)
    Browser->>setup.js: navigator.connection
    setup.js->>setup.js: const connection = navigator.connection\nuse connection?.effectiveType || "Unknown"\nuse connection?.downlink || "Unknown"\nuse connection?.rtt || "Unknown"

    alt Data present
        setup.js->>UI: update network-type, network-downlink, network-rtt (formatted)
    else Missing data
        setup.js->>UI: update fields with "Unknown" (or formatted "Unknown" strings)
    end

    Note right of setup.js #FFF4E5: decision logic (offline/slow/online) unchanged
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • nerdCopter

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 82c11c6 and f67edc8.

📒 Files selected for processing (1)
  • src/js/tabs/setup.js (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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 (2)
src/js/tabs/setup.js (2)

500-503: Don’t default missing downlink/rtt to 0 — it misclassifies “unknown” as “slow”.

Setting numeric fallbacks to 0 makes the slow/online decision treat unsupported/unknown values as slow, while the UI shows “Unknown”. Use presence checks and avoid coercing to 0; also consider separating connection.type (for “none”) from effectiveType (for “2g/3g/4g”) to keep the logic correct.

Apply this diff to make the values presence-aware and add legacy prefixes:

-            const connection = navigator.connection;
-            const type = connection?.effectiveType || "unknown";
-            const downlink = connection?.downlink || 0;
-            const rtt = connection?.rtt || 0;
+            const connection =
+                navigator.connection || navigator.mozConnection || navigator.webkitConnection;
+            // effectiveType is used for "slow-2g/2g/3g/4g" classification
+            const effectiveType = connection?.effectiveType ?? "unknown";
+            // connection.type is used for "none"/wifi/cellular/etc.
+            const connType = connection?.type ?? "unknown";
+            const downlink = typeof connection?.downlink === "number" ? connection.downlink : undefined;
+            const rtt = typeof connection?.rtt === "number" ? connection.rtt : undefined;

Then adjust the decision logic to use the new vars (outside the changed hunk, shown here for clarity):

if (!networkStatus || !navigator.onLine || connType === "none") {
  statusText = i18n.getMessage("initialSetupNetworkInfoStatusOffline");
} else if (
  effectiveType === "slow-2g" ||
  effectiveType === "2g" ||
  (downlink !== undefined && downlink < 0.115) ||
  (rtt !== undefined && rtt > 1000)
) {
  statusText = i18n.getMessage("initialSetupNetworkInfoStatusSlow");
} else {
  statusText = i18n.getMessage("initialSetupNetworkInfoStatusOnline");
}

This preserves “unknown” as unknown (not slow), and keeps “offline” detection tied to connection.type === "none" and navigator.onLine.


515-517: Truthiness check hides valid 0 values; reuse computed vars and prefer i18n for “Unknown”.

Using connection?.downlink ? ... : "Unknown" treats 0 as unknown. Reuse the computed vars and use Number.isFinite to decide display. Also, keep casing consistent and consider localizing “Unknown”.

Apply this diff:

-            $(".network-type").text(connection?.effectiveType || "Unknown");
-            $(".network-downlink").text(connection?.downlink ? `${connection.downlink} Mbps` : "Unknown");
-            $(".network-rtt").text(connection?.rtt ? `${connection.rtt} ms` : "Unknown");
+            // If an i18n key exists (e.g., "initialSetupNetworkInfoUnknown"), prefer that over the literal "Unknown".
+            const unknownLabel = "Unknown"; // or i18n.getMessage("initialSetupNetworkInfoUnknown")
+            $(".network-type").text(effectiveType !== "unknown" ? effectiveType : unknownLabel);
+            $(".network-downlink").text(Number.isFinite(downlink) ? `${downlink} Mbps` : unknownLabel);
+            $(".network-rtt").text(Number.isFinite(rtt) ? `${rtt} ms` : unknownLabel);

Optional follow-up: If you keep type as the name, consider aligning the capitalization: either store "Unknown" or map "unknown" to the display label consistently.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0259c8a and 82c11c6.

📒 Files selected for processing (1)
  • src/js/tabs/setup.js (2 hunks)

@haslinghuis haslinghuis moved this to App in 2025.12.0 Aug 17, 2025
@haslinghuis haslinghuis added this to the 11.0 milestone Aug 17, 2025
@nerdCopter nerdCopter self-requested a review August 17, 2025 18:03
VitroidFPV and others added 2 commits August 26, 2025 22:34
Co-authored-by: Mark Haslinghuis <[email protected]>
Co-authored-by: Mark Haslinghuis <[email protected]>
Copy link

Copy link
Contributor

Preview URL: https://f67edc86.betaflight-configurator.pages.dev

@haslinghuis haslinghuis merged commit 4e0fb3a into betaflight:master Aug 26, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from App to Done in 2025.12.0 Aug 26, 2025
@haslinghuis haslinghuis mentioned this pull request Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants