-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix intermittent invalid state error in loadfile (cli) #4642
Conversation
WalkthroughLazy-initialize and reset the CLI snippet preview modal reference; guard activation binding and dialog scroll reset in the modal initializer; ensure confirm handler is rebound with current fileName and the modal is opened/closed via the dialog element when needed. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant CLI as CLI Tab
participant Init as initializeModalDialog
participant Dialog as <#snippetpreviewdialog>
User->>CLI: Click "Preview Commands" (fileName)
CLI->>CLI: Ensure self.GUI.snippetPreviewWindow exists
alt modal missing
CLI->>Init: initializeModalDialog("#snippetpreviewdialog", ..., confirmHandler)
Init-->>CLI: returns dialog reference
end
CLI->>Dialog: set preview content
CLI->>Dialog: attach/bind confirm handler (captures fileName)
CLI->>Dialog: showModal()
note right of Dialog: User reviews preview
User->>Dialog: Click Confirm
Dialog->>CLI: trigger confirm handler
CLI->>Dialog: close()
CLI->>CLI: executeSnippet(fileName)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🔇 Additional comments (2)
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 |
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.
|
Preview URL: https://pr4642.betaflight-app.pages.dev |
How to reproduce: when using load from file a second time in CLI to restore a diff:
Summary by CodeRabbit
Bug Fixes
Refactor