Skip to content

fix(editor): safeguard event unregistrations against undefined values#1125

Open
mrueg wants to merge 1 commit into
Vinzent03:masterfrom
mrueg:fix/editor-unregistration-safety
Open

fix(editor): safeguard event unregistrations against undefined values#1125
mrueg wants to merge 1 commit into
Vinzent03:masterfrom
mrueg:fix/editor-unregistration-safety

Conversation

@mrueg

@mrueg mrueg commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Description

This PR safeguards the event handler unregistrations in the editor features (SignsFeature and LineAuthoringFeature) against undefined values during feature deactivation / plugin unloading, and removes a dead field.


The Issue

When features are deactivated (or when the plugin is unloaded), EditorIntegration calls deactivateFeature() on each feature. If a feature was never activated (for example, if the feature is disabled in settings), its event variables (e.g. workspaceLeafChangeEvent, fileRenameEvent, fileOpenEvent, etc.) remain undefined.

Calling this.plg.app.workspace.offref(this.workspaceLeafChangeEvent!) directly with undefined on deactivation is unsafe.

Additionally:

  • SignsFeature declared and unregistered gutterContextMenuEvent, but it was never registered or used.

The Fix

  1. Safety Checks: Updated destroyEventHandlers() in both features to verify that event references exist before calling offref() on them:
    if (this.workspaceLeafChangeEvent) {
        this.plg.app.workspace.offref(this.workspaceLeafChangeEvent);
        this.workspaceLeafChangeEvent = undefined;
    }
  2. Dead Code Cleanup: Removed the unused gutterContextMenuEvent declaration and unregistration from SignsFeature.

Verification

  • Verified that compiler checks (npm run tsc) pass cleanly.
  • Verified that formatting and linter checks (npm run lint) pass with no warnings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant