Skip to content

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Sep 27, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Servos tab now appears when either servos or wing capability is enabled, improving visibility across configurations.
    • Connection/disconnection now reliably cleans up UI state and timers, reducing stale UI and connection glitches.
  • Improvements

    • Virtual connection handling and problem-reporting behavior made more reliable, improving status accuracy and diagnostics.

@haslinghuis haslinghuis added this to the 2025.12 milestone Sep 27, 2025
@haslinghuis haslinghuis self-assigned this Sep 27, 2025
Copy link
Contributor

coderabbitai bot commented Sep 27, 2025

Walkthrough

Servos tab exposure now depends on build options containing either "USE_SERVOS" or "USE_WING". Serial backend centralizes connect/disconnect cleanup, updates virtual-connection timestamps to use globalThis.vm, consolidates problem-reporting, and may inject "servos" into GUI.allowedTabs when USE_WING is present. No public APIs changed.

Changes

Cohort / File(s) Summary of Changes
Tab visibility logic
src/js/utils/updateTabList.js
- Servos tab enablement now checks if any of ["USE_SERVOS","USE_WING"] appears in FC.CONFIG?.buildOptions (uses some(...)) instead of requiring isExpertModeEnabled && .... Other tab checks unchanged.
Serial backend control flow & GUI injection
src/js/serial_backend.js
- Centralized disconnect sequence when already connected (GUI cleanup: timeouts/intervals/tab switch cleanup).
- connectDisconnect now disconnects only when isConnected is true; finish callback wired via mspHelper.setArmingEnabled.
- Use globalThis.vm for virtual-connection timestamps (onOpenVirtual, onClosed) and update CONNECTION handling.
- Introduced checkReportProblem helper and switched problem iteration to for...of.
- In finishOpen, if FC.CONFIG?.buildOptions includes USE_WING and "servos" is not present, push "servos" into GUI.allowedTabs.
- Replaced indexOf(...) !== -1 checks with includes(...) for board-type conditions.

Sequence Diagram(s)

sequenceDiagram
  participant UI
  participant TabChecker as updateTabList.js
  participant Serial as serial_backend.js
  participant FC as FC.CONFIG
  participant GUI

  Note over FC: After config available / on connection
  Serial->>FC: read buildOptions
  Serial->>Serial: finishOpen()
  alt FC.buildOptions includes "USE_WING"
    Serial->>GUI: add "servos" to allowedTabs if missing
    Note right of GUI #e6ffed: allowed tabs updated
  end

  UI->>TabChecker: updateTabList()
  TabChecker->>FC: check buildOptions
  alt includes "USE_SERVOS" or "USE_WING"
    TabChecker->>GUI: enable "servos" tab
  else
    TabChecker->>GUI: leave "servos" disabled
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Fix serial #4449 — modifies serial connection/disconnection and cleanup logic in serial stack (related to connect/disconnect changes).
  • Refactor: Use serial path #4548 — touches src/js/serial_backend.js connect/disconnect and virtual-connection handling (overlaps on onOpenVirtual/timestamp behavior).

Suggested reviewers

  • nerdCopter
  • VitroidFPV
  • KarateBrot

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is completely empty, with no content provided by the author. The description template for this repository contains detailed guidelines about pull request expectations, including coding style, commit structure, issue references, and CI requirements. None of these sections or any contextual information about the changes, testing, or rationale have been included. An empty description fails to meet even the most basic documentation standards for a pull request. The author should add a description that explains what problem this fixes (why the servo tab needs to be enabled for WING define), what changes were made to achieve this, and how it was tested. If this fixes a specific GitHub issue, it should include "Fixes #" as mentioned in the template. The description should also note any additional refactoring performed in serial_backend.js and explain why those changes were necessary or beneficial.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Enable servo tab for WING define" clearly and accurately describes the main change in this pull request. The changeset modifies the tab activation logic to include the "USE_WING" build option alongside "USE_SERVOS" for enabling the Servos tab, and the title directly references this functionality. While the changes also include some refactoring in serial_backend.js (such as cleanup logic and problem reporting helpers), the primary functional change is indeed enabling the servo tab when the WING define is present, which makes the title appropriately focused on the most important change from a user perspective.
✨ 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

Tip

🧪 Early access (models): enabled

We are currently testing Sonnet 4.5 code review models, which should lead to better review quality. However, this model may result in higher noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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

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: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac661b6 and 8a795df.

📒 Files selected for processing (1)
  • src/js/utils/updateTabList.js (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: mituritsyn
PR: betaflight/betaflight-configurator#4526
File: src/js/gui.js:43-43
Timestamp: 2025-06-20T12:35:49.283Z
Learning: In the Betaflight Configurator codebase, tabs in `defaultCloudBuildTabOptions` are conditionally displayed based on firmware build options. The logic in `serial_backend.js` checks `FC.CONFIG.buildOptions` and only adds tabs to `GUI.allowedTabs` if the firmware was built with support for that feature.
📚 Learning: 2025-06-20T12:35:49.283Z
Learnt from: mituritsyn
PR: betaflight/betaflight-configurator#4526
File: src/js/gui.js:43-43
Timestamp: 2025-06-20T12:35:49.283Z
Learning: In the Betaflight Configurator codebase, tabs in `defaultCloudBuildTabOptions` are conditionally displayed based on firmware build options. The logic in `serial_backend.js` checks `FC.CONFIG.buildOptions` and only adds tabs to `GUI.allowedTabs` if the firmware was built with support for that feature.

Applied to files:

  • src/js/utils/updateTabList.js
🧬 Code graph analysis (1)
src/js/utils/updateTabList.js (1)
src/js/fc.js (1)
  • FC (131-990)

@haslinghuis haslinghuis moved this to App in 2025.12.0 Sep 27, 2025
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/utils/updateTabList.js (1)

11-13: Show Servos without expert mode: good; add optional chaining on includes to avoid rare NPE.

If buildOptions is briefly undefined during early UI init, calling .includes(...) can throw. Guard the method call.

Apply:

-    $("#tabs ul.mode-connected li.tab_servos").toggle(
-        ["USE_SERVOS", "USE_WING"].some((option) => FC.CONFIG?.buildOptions?.includes(option)),
-    );
+    $("#tabs ul.mode-connected li.tab_servos").toggle(
+        ["USE_SERVOS", "USE_WING"].some((option) => FC.CONFIG?.buildOptions?.includes?.(option)),
+    );

For consistency, consider applying the same includes?.(...) guard to the GPS line in this file as well.

Based on learnings

src/js/serial_backend.js (1)

620-624: Unify USE_WING predicate and confirm defaultCloudBuildTabOptions includes “servos”
defaultCloudBuildTabOptions already defines "servos", so the tab appears when USE_SERVOS is present. To align the special‐case check with the flag‐lookup used elsewhere, apply:

-        if (FC.CONFIG.buildOptions.some((opt) => opt.includes("USE_WING")) && !GUI.allowedTabs.includes("servos")) {
+        if (["USE_WING"].some((flag) => FC.CONFIG.buildOptions.includes(flag)) && !GUI.allowedTabs.includes("servos")) {
             GUI.allowedTabs.push("servos");
         }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a795df and 4f9f6fc.

📒 Files selected for processing (2)
  • src/js/serial_backend.js (1 hunks)
  • src/js/utils/updateTabList.js (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: mituritsyn
PR: betaflight/betaflight-configurator#4526
File: src/js/gui.js:43-43
Timestamp: 2025-06-20T12:35:49.283Z
Learning: In the Betaflight Configurator codebase, tabs in `defaultCloudBuildTabOptions` are conditionally displayed based on firmware build options. The logic in `serial_backend.js` checks `FC.CONFIG.buildOptions` and only adds tabs to `GUI.allowedTabs` if the firmware was built with support for that feature.
📚 Learning: 2025-06-20T12:35:49.283Z
Learnt from: mituritsyn
PR: betaflight/betaflight-configurator#4526
File: src/js/gui.js:43-43
Timestamp: 2025-06-20T12:35:49.283Z
Learning: In the Betaflight Configurator codebase, tabs in `defaultCloudBuildTabOptions` are conditionally displayed based on firmware build options. The logic in `serial_backend.js` checks `FC.CONFIG.buildOptions` and only adds tabs to `GUI.allowedTabs` if the firmware was built with support for that feature.

Applied to files:

  • src/js/serial_backend.js
  • src/js/utils/updateTabList.js
📚 Learning: 2025-09-19T20:42:20.332Z
Learnt from: haslinghuis
PR: betaflight/betaflight-configurator#4510
File: src/js/msp.js:384-391
Timestamp: 2025-09-19T20:42:20.332Z
Learning: Complex MSP duplicate handling fixes in Betaflight Configurator can cause infinite loading messages when changing tabs due to disruption of the callback resolution mechanism. Simple code-only duplicate detection (using this.callbacks.some((instance) => instance.code === code)) is the safer approach that preserves tab switching functionality.

Applied to files:

  • src/js/utils/updateTabList.js
🧬 Code graph analysis (2)
src/js/serial_backend.js (2)
src/js/fc.js (1)
  • FC (131-990)
src/js/gui.js (1)
  • GUI (465-465)
src/js/utils/updateTabList.js (1)
src/js/fc.js (1)
  • FC (131-990)

@VitroidFPV
Copy link
Member

Ignore sonar cloud?

Copy link

Copy link
Contributor

Preview URL: https://pr4635.betaflight-app.pages.dev

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: 1

🧹 Nitpick comments (1)
src/js/serial_backend.js (1)

673-673: Consider modernizing the adjacent jQuery array check for consistency.

Line 673 correctly uses the native includes method, but line 667 still uses the older jQuery $.inArray. For consistency, consider updating line 667 as well:

-                if ($.inArray(tabName, classes) >= 0) {
+                if (classes.includes(tabName)) {
                     found = true;
                 }
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4f9f6fc and 28f5903.

📒 Files selected for processing (1)
  • src/js/serial_backend.js (8 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: mituritsyn
PR: betaflight/betaflight-configurator#4526
File: src/js/gui.js:43-43
Timestamp: 2025-06-20T12:35:49.283Z
Learning: In the Betaflight Configurator codebase, tabs in `defaultCloudBuildTabOptions` are conditionally displayed based on firmware build options. The logic in `serial_backend.js` checks `FC.CONFIG.buildOptions` and only adds tabs to `GUI.allowedTabs` if the firmware was built with support for that feature.
📚 Learning: 2025-06-20T12:35:49.283Z
Learnt from: mituritsyn
PR: betaflight/betaflight-configurator#4526
File: src/js/gui.js:43-43
Timestamp: 2025-06-20T12:35:49.283Z
Learning: In the Betaflight Configurator codebase, tabs in `defaultCloudBuildTabOptions` are conditionally displayed based on firmware build options. The logic in `serial_backend.js` checks `FC.CONFIG.buildOptions` and only adds tabs to `GUI.allowedTabs` if the firmware was built with support for that feature.

Applied to files:

  • src/js/serial_backend.js
🧬 Code graph analysis (1)
src/js/serial_backend.js (6)
src/js/gui.js (1)
  • GUI (465-465)
src/js/msp/MSPHelper.js (1)
  • mspHelper (2937-2937)
src/js/utils/AutoDetect.js (1)
  • mspHelper (19-19)
src/js/bit.js (1)
  • bit_check (1-3)
src/js/fc.js (1)
  • FC (131-990)
src/js/localization.js (1)
  • i18n (7-7)
🔇 Additional comments (4)
src/js/serial_backend.js (4)

113-124: LGTM! Disconnection sequence centralized correctly.

The refactored disconnection logic properly centralizes cleanup (timeouts, intervals, tab switching) and ensures finishClose is called with the appropriate callback. The use of optional chaining on mspHelper is a good defensive practice.


398-400: LGTM! Modern globalThis.vm usage.

The migration from window.vm to globalThis.vm is appropriate and improves cross-environment compatibility. The consistent use of optional chaining and deferred execution across all three locations ensures Vue components are properly mounted before timestamp updates.

Also applies to: 567-569, 712-714


463-469: LGTM! Good refactoring to extract helper function.

The extraction of checkReportProblem as a top-level helper reduces code duplication and improves maintainability. The function has a clear single responsibility and is used consistently in checkReportProblems.


512-514: LGTM! Modern iteration syntax.

The change from forEach to for...of is a minor modernization that improves readability without affecting functionality.

@haslinghuis haslinghuis merged commit 9bd2927 into betaflight:master Sep 29, 2025
8 checks passed
@haslinghuis haslinghuis deleted the fix-wing-servo branch September 29, 2025 18:31
@github-project-automation github-project-automation bot moved this from App to Done in 2025.12.0 Sep 29, 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