Skip to content

Commit 03c5dbd

Browse files
committed
fix(git): guard CommandManager.get(...).setChecked against early panel events
WorkspaceManager.EVENT_WORKSPACE_PANEL_SHOWN/HIDDEN can fire during project-open before the Git extension's init flow has registered CMD_GIT_TOGGLE_PANEL. CommandManager.get(...) then returns undefined and the .setChecked(...) call throws TypeError, which surfaced as "Exception in 'panelShown' listener" in the Git main.js stack. Wrap the lookup + setChecked in a small _setTogglePanelChecked helper that no-ops when the command isn't registered yet — init will sync the checked state on its own once it runs. Apply at the three call sites (panel-shown listener, panel-hidden listener, and toggle()).
1 parent 2399011 commit 03c5dbd

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/extensions/default/Git/src/Panel.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ define(function (require, exports) {
931931
gitPanel.setVisible(bool);
932932

933933
// Mark menu item as enabled/disabled.
934-
CommandManager.get(Constants.CMD_GIT_TOGGLE_PANEL).setChecked(bool);
934+
_setTogglePanelChecked(bool);
935935

936936
if (bool) {
937937
$("#git-toolbar-icon").removeClass("forced-hidden");
@@ -1510,21 +1510,33 @@ define(function (require, exports) {
15101510
handleGitCommit(lastCommitMessage[ProjectManager.getProjectRoot().fullPath], false, COMMIT_MODE.DEFAULT);
15111511
});
15121512

1513+
// The toggle-panel command is registered in the extension's init flow.
1514+
// These workspace-panel events can fire during project-open before
1515+
// init has run (race during boot), so CommandManager.get can return
1516+
// undefined — the menu just hasn't been wired up yet. Skip the
1517+
// setChecked call in that window; init will sync state on its own.
1518+
function _setTogglePanelChecked(bool) {
1519+
const command = CommandManager.get(Constants.CMD_GIT_TOGGLE_PANEL);
1520+
if (command) {
1521+
command.setChecked(bool);
1522+
}
1523+
}
1524+
15131525
// When the panel tab is closed externally (e.g. via the × button),
15141526
// update the toolbar icon and menu checked state to stay in sync.
15151527
WorkspaceManager.on(WorkspaceManager.EVENT_WORKSPACE_PANEL_HIDDEN, function (event, panelID) {
15161528
if (panelID === "main-git.panel" && gitPanel) {
15171529
Main.$icon.toggleClass("on", false);
15181530
Main.$icon.toggleClass("selected-button", false);
1519-
CommandManager.get(Constants.CMD_GIT_TOGGLE_PANEL).setChecked(false);
1531+
_setTogglePanelChecked(false);
15201532
Preferences.set("panelEnabled", false);
15211533
}
15221534
// When the bottom panel container is collapsed, deselect the icon
15231535
// but don't save preference — the panel is still logically open.
15241536
if (panelID === WorkspaceManager.DEFAULT_PANEL_ID && Main.$icon) {
15251537
Main.$icon.toggleClass("on", false);
15261538
Main.$icon.toggleClass("selected-button", false);
1527-
CommandManager.get(Constants.CMD_GIT_TOGGLE_PANEL).setChecked(false);
1539+
_setTogglePanelChecked(false);
15281540
}
15291541
});
15301542

@@ -1535,7 +1547,7 @@ define(function (require, exports) {
15351547
const isGitActive = (panelID === "main-git.panel");
15361548
Main.$icon.toggleClass("on", isGitActive);
15371549
Main.$icon.toggleClass("selected-button", isGitActive);
1538-
CommandManager.get(Constants.CMD_GIT_TOGGLE_PANEL).setChecked(isGitActive);
1550+
_setTogglePanelChecked(isGitActive);
15391551
});
15401552

15411553
exports.init = init;

0 commit comments

Comments
 (0)