-
-
Notifications
You must be signed in to change notification settings - Fork 998
Fix intermittent invalid state error in loadfile (cli) #4642
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughRefactors CLI tab snippet preview dialog management to use a direct DOM Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CLI as CLI Tab
participant DOM as Snippet Dialog (#snippetpreviewdialog)
User->>CLI: Click "Preview Commands"
CLI->>CLI: Lookup dialog element
alt Dialog found
CLI->>DOM: Attach confirm handler (captures fileName)
opt If not already open
CLI->>DOM: showModal()
end
Note over DOM,CLI: User reviews commands
User->>DOM: Click Confirm
DOM->>CLI: Confirm event
CLI->>DOM: close()
CLI->>CLI: Execute commands
else Dialog missing
CLI->>CLI: Abort / no-op
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (3 warnings)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
|
Preview URL: https://pr4642.betaflight-app.pages.dev |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/js/tabs/cli.js (1)
169-171
: Consider removing redundant initialization flag.The
self.GUI.snippetPreviewWindow
property is now primarily used as an initialization flag, but since the dialog element is retrieved directly each time via$("#snippetpreviewdialog")[0]
, this tracking may be unnecessary. The current implementation works correctly, but simplifying this could reduce cognitive overhead.Potential cleanup:
- // Mark as initialized after first use - if (!self.GUI.snippetPreviewWindow) { - self.GUI.snippetPreviewWindow = snippetDialog; - }You could also remove the property declaration from line 23 if it's not used elsewhere.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/js/tabs/cli.js
(1 hunks)
🔇 Additional comments (2)
src/js/tabs/cli.js (2)
148-154
: LGTM! Clean refactoring with proper null guard.The direct DOM reference and null check prevent potential errors when closing the dialog.
156-179
: Excellent fix for the invalid state error!The refactoring correctly addresses the intermittent issue by:
- Adding early validation of the dialog element
- Always updating the click handler to capture the current fileName
- Guarding
showModal()
with!snippetDialog.hasAttribute("open")
to prevent calling showModal on an already-open dialog (which throws InvalidStateError)The direct DOM manipulation is more reliable than the previous modal wrapper pattern.
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.
- approving, shallow test: flashed and pasted.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor