Fix JavaScript Programming tab issues (#2453)#2460
Conversation
Resolves multiple bugs in the JavaScript Programming tab mentioned in iNavFlight#2453 1. IntelliSense contamination with browser APIs - Configured Monaco editor to use ES2020 lib only - Excludes DOM/browser APIs (navigator, document, etc.) - Preserves Math and standard JavaScript features 2. Override property validation errors - Restored override.js API definitions - Updated to use OPERATION constants from inav_constants.js - Enables proper IntelliSense for override.vtx.power, etc. 3. Unsaved changes warning behavior Implementation details: - monaco_loader.js: Added lib: ['es2020'] to compiler options - override.js: Restored from git history, updated with OPERATION constants - serial_backend.js: Check isDirty before disconnect, clear flag after confirm - configurator_main.js: Check isDirty before tab switch - javascript_programming.js: Simplified cleanup() to only dispose editor Testing: - IntelliSense no longer suggests browser APIs - Override properties validate correctly - Unsaved changes warning shows exactly once - Cancel properly prevents disconnect/tab switch - Subsequent actions work correctly after cancel Files changed: - js/transpiler/editor/monaco_loader.js - js/transpiler/api/definitions/override.js (restored) - js/transpiler/api/definitions/index.js - js/transpiler/api/types.js - js/serial_backend.js - js/configurator_main.js - tabs/javascript_programming.js
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
User description
Summary
Fixes multiple bugs in the JavaScript Programming tab reported in issue #2453.
Issues Fixed
1. IntelliSense Contamination with Browser APIs ✓
Problem: Monaco editor autocomplete was suggesting browser-only APIs like
navigator,document,windowwhich are not available in the INAV JavaScript runtime.Solution: Configured Monaco editor TypeScript compiler to use only ES2020 core library, excluding DOM/browser APIs while preserving standard JavaScript features like Math.
Files:
js/transpiler/editor/monaco_loader.js2. Override Property Validation Errors ✓
Problem: Using
override.vtx.powerand other override properties caused "Cannot read properties of undefined" errors in IntelliSense.Solution:
override.jsAPI definitions that were previously deletedinav_constants.jsFiles:
js/transpiler/api/definitions/override.js(restored and updated)js/transpiler/api/definitions/index.jsjs/transpiler/api/types.js3. Unsaved Changes Warning Behavior ✓
Problem:
Solution:
isDirtyflag after user confirms to prevent duplicate warnings during subsequent tab switchesFiles:
js/serial_backend.js- Check before disconnectjs/configurator_main.js- Check before tab switchtabs/javascript_programming.js- Simplified cleanupImplementation Details
Monaco Editor Configuration
Override API Definitions
OPERATION.OVERRIDE_THROTTLE_SCALE, etc.Unsaved Changes Flow
Disconnect:
isDirtyin serial_backend.jsisDirtyflag, proceed with disconnectTab Switch:
isDirtyin configurator_main.jsCleanup:
Testing Performed
✅ IntelliSense no longer suggests
navigator,document,window✅ IntelliSense correctly validates
override.vtx.power,override.throttle, etc.✅ Math and standard JavaScript features still available
✅ Unsaved changes warning appears exactly once on disconnect
✅ Clicking "Cancel" prevents disconnect
✅ Unsaved changes warning appears exactly once on tab switch
✅ Clicking "Cancel" prevents tab switch
✅ Subsequent disconnect/tab switch attempts work correctly after cancel
Files Changed
js/transpiler/editor/monaco_loader.js- Monaco configurationjs/transpiler/api/definitions/override.js- Restored API definitionsjs/transpiler/api/definitions/index.js- Export override definitionsjs/transpiler/api/types.js- Generate override TypeScript interfacejs/serial_backend.js- Check unsaved changes before disconnectjs/configurator_main.js- Check unsaved changes before tab switchtabs/javascript_programming.js- Simplified cleanup functionRelated Issues
Closes #2453
PR Type
Bug fix
Description
Fixed IntelliSense contamination by configuring Monaco editor to use ES2020 library only, excluding browser APIs
Restored and updated override API definitions with OPERATION constants for proper IntelliSense validation
Fixed unsaved changes warning behavior by checking before disconnect/tab switch, preventing duplicate dialogs
Simplified cleanup function to only dispose editor resources after user confirmation
Diagram Walkthrough
flowchart LR A["User Action<br/>Disconnect/Tab Switch"] --> B["Check isDirty<br/>in serial_backend.js<br/>or configurator_main.js"] B --> C{"Unsaved<br/>Changes?"} C -->|No| D["Proceed with Action"] C -->|Yes| E["Show Warning Dialog"] E --> F{"User<br/>Confirms?"} F -->|Cancel| G["Return Early<br/>Action Cancelled"] F -->|Confirm| H["Clear isDirty Flag"] H --> D D --> I["cleanup() Disposes<br/>Editor Resources"]File Walkthrough
configurator_main.js
Check unsaved changes before tab switchjs/configurator_main.js
tab switch
isDirtyflag is setserial_backend.js
Check unsaved changes before disconnectjs/serial_backend.js
disconnect
isDirtyflag is setisDirtyflag after user confirms to prevent duplicate warningsmonaco_loader.js
Configure Monaco to exclude browser APIsjs/transpiler/editor/monaco_loader.js
lib: ['es2020']to Monaco compiler optionsDOM/browser APIs
navigator, document, window
javascript_programming.js
Simplify cleanup and improve dirty trackingtabs/javascript_programming.js
dirty during decompilation
isDirtyflag when codeis modified
before cleanup is called
serial_backend.js and configurator_main.js
override.js
Restore and define override API operationsjs/transpiler/api/definitions/override.js
operations
channel, loiter radius, and min ground speed
index.js
Export override API definitionsjs/transpiler/api/definitions/index.js
override.jsAPI definitionstypes.js
Generate TypeScript interface for override APIjs/transpiler/api/types.js