Skip to content

fix: cleans up plugin event listeners on update and unmount properly#1272

Open
Ishita-190 wants to merge 5 commits intoasyncapi:masterfrom
Ishita-190:ishi
Open

fix: cleans up plugin event listeners on update and unmount properly#1272
Ishita-190 wants to merge 5 commits intoasyncapi:masterfrom
Ishita-190:ishi

Conversation

@Ishita-190
Copy link
Copy Markdown

Description

Changes proposed in this pull request:

  • created a handler function for each event, store it in the eventHandlers Map which will then be reused for both pm.on and pm.off
  • Added componentWillUnmount to AsyncApiComponent for proper event listener cleanup.

verified this using a test, it's working properly :

Screenshot 2026-04-27 002536

Related issue(s)

Fixes #1235

Copy link
Copy Markdown
Member

@AceTheCreator AceTheCreator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Ishita-190

Can you fix your failing tests? Once done, i'll give it a review

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Member

@AceTheCreator AceTheCreator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left you a review :)

}

class AsyncApiComponent extends Component<AsyncApiProps, AsyncAPIState> {
componentWillUnmount() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the lifecycle placement hard to read. I don't think componentWillUnmount should be at the top-level

this.props.onPluginEvent!(eventName, data);
};
}
private eventHandlers = new Map<string, (data: unknown) => void>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this readonly

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.

Event listeners are not properly cleaned up in AsyncApiComponent

2 participants