Fix runtime menu refresh crash when application menus are not yet received (#9762)#10070
Fix runtime menu refresh crash when application menus are not yet received (#9762)#10070dpage wants to merge 1 commit into
Conversation
…rg#9762) refreshMenus() rebuilt the application menu from the module-level cachedMenus, which is only populated once the renderer sends its menu definition via the 'setMenus' IPC. When a menu refresh was triggered before that happened - e.g. an auto-update event, or the user closing the window while the UI was still loading - cachedMenus was undefined and bindMenuClicks() crashed with 'Cannot read properties of undefined (reading map)', surfacing as an uncaught-exception dialog. Guard refreshMenus() so it bails out when there are no cached menus to rebuild. Closes pgadmin-org#9762
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdded a safety check in ChangesMenu Refresh Safety Check
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Pull request overview
Prevents the Electron runtime main-process crash that could occur when refreshMenus() is triggered before the renderer has sent the initial menu definition via setMenus IPC.
Changes:
- Add an early return in
refreshMenus()whencachedMenusis not yet populated, avoiding amapdereference crash. - Document the fix in the v9.16 release notes (Issue #9762).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| runtime/src/js/menu.js | Guard refreshMenus() to avoid rebuilding menus when cachedMenus is still unset. |
| docs/en_US/release_notes_9_16.rst | Add a v9.16 bug-fix note referencing Issue #9762. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
TypeError: Cannot read properties of undefined (reading 'map')inmenu.js, surfacing as an "A JavaScript error occurred in the main process" dialog.refreshMenus()rebuilds the application menu from the module-levelcachedMenus, which is only populated once the renderer sends its menu definition via thesetMenusIPC. If a menu refresh is triggered before that happens — e.g. an auto-update event on macOS, or the user closing the window (which firesupdateConfigAndMenus('error-close', ...)) while the UI is still loading/blank —cachedMenusisundefinedandbindMenuClicks()dereferences it.refreshMenus()so it bails out early when there are no cached menus to rebuild. This matches the existing early-return style in the same file.This explains the reporters' symptom of the error box appearing when clicking the window's X while the UI was stuck on a blank/loading screen, and the macOS variant triggered via the auto-updater.
Test plan
node --checkpasses on the modifiedmenu.js.Closes #9762
Summary by CodeRabbit