Skip to content

[FEAT] Add Plugin cleanup support when BpmnVisualization is disposed #475

@tbouffard

Description

@tbouffard

Is your feature request related to a problem? Please describe.

Plugins in bpmn-visualization-addons can register event listeners, allocate objects, keep internal references, or start timers.
Since the core library now provides a dispose() method on BpmnVisualization (see process-analytics/bpmn-visualization-js#3415), the core instance can clean up resources, but plugins still cannot.
This may create memory leaks in long-running applications or SPA environments.

Describe the solution you'd like

Add a new plugin lifecycle hook to let plugins release their resources when the underlying BpmnVisualization is disposed.

Proposed changes:

  • Add a new optional method onDispose(): void on plugins
  • Add a new onConfigure(bv) hook for consistency (as onDispose), while keeping configure(bv) for backward compatibility
  • During disposal, the addons wrapper should:
    • call plugin.onDispose?.()
    • then call bpmnVisualization.dispose()

Example API:

export interface Plugin {
  readonly id: string;

  onConfigure?(bv: BpmnVisualization): void;
  onDispose?(): void;

  // backward compatibility, probably to replace by only keeping onConfigure
  configure?(bv: BpmnVisualization): void;
}

Describe alternatives you've considered

  • Using only configure and not adding onDispose, but this leaves plugins without a cleanup mechanism.
  • Naming the method dispose(), but this can be confusing because the core object already has its own dispose().
    onDispose makes it clear that it is a lifecycle hook.

Additional context

This hook will help plugin authors properly clean up:

  • DOM or graph event listeners
  • timers or intervals
  • references to the BpmnVisualization instance
  • cached data or internal state

It also aligns plugin lifecycle management with the new disposal capabilities introduced in the core library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions