feat: add plugin lifecycle hooks for load and dispose#540
Merged
Conversation
Extend the Plugin interface with four optional lifecycle hooks so plugins can react to the BpmnVisualization lifecycle without any client code wiring: - onDispose: called when the instance is disposed, before the underlying resources are released - onBeforeLoad: called at the start of each load, before the BPMN source is processed - onLoadSuccess: called after a load has succeeded - onLoadError: called with the thrown error when a load fails, before the error is rethrown BpmnVisualization overrides dispose() and load() to notify every registered plugin through the forEachPlugin helper. load() wraps the delegation in a try/catch so onLoadError fires on failure and onLoadSuccess only on success. Enabling noImplicitOverride in tsconfig enforces the override modifier on these new overrides. Document the hooks in the README, including how to pass options to a plugin via onConfigure using module augmentation of GlobalOptions, namespacing properties under a per-plugin object to avoid name clashes.
♻️ Preview destroyed
🤖 Powered by surge-preview |
|||||||||
Lock the onLoadError contract by checking the hook is called with the caught error, not just that it is invoked.
|
This was referenced Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




What
Extend the plugin system with four new optional lifecycle hooks on the
Plugininterface, so plugins can react to theBpmnVisualizationlifecycle without any client code wiring:onDispose: called when the instance is disposed, before the underlying resources are released.onBeforeLoad: called at the start of eachload, before the BPMN source is processed.onLoadSuccess: called after aloadhas succeeded.onLoadError(error): called with the thrown error when aloadfails, before the error is rethrown to the caller.Why
Until now the only lifecycle hook was
onConfigure(post-construction). Plugins had no way to run logic around load and dispose, which are the two key moments where a plugin typically needs to set up, refresh, or release resources. These hooks fill that gap while keeping everything opt-in: a plugin implements only the hooks it needs, and plugins without a given hook are simply skipped.How
BpmnVisualizationoverridesdispose()andload()and notifies every registered plugin through a sharedforEachPluginhelper.load()wraps the delegation tosuper.load()in atry/catch: on failure it callsonLoadErrorthen rethrows, so callers still observe the error;onLoadSuccessonly runs on the success path.onBeforeLoadalways runs first.noImplicitOverrideis enabled intsconfigto enforce theoverridemodifier on the new overrides.Naming
onLoadSuccessis named for the success-only contract (it is intentionally skipped on error), pairing clearly withonLoadError.onLoadErrorreceives the caught error so plugins can react to what failed.Documentation
The README documents all five hooks and adds a worked example showing how to pass options to a plugin via
onConfigureusing module augmentation ofGlobalOptions, namespacing properties under a per-plugin object to avoid name clashes.Tests
Added coverage for each hook: that the hook fires the expected number of times, that plugins missing the hook are ignored without error, and the success/error exclusivity (success does not trigger
onLoadError, and a failing load still triggersonBeforeLoadwhile skippingonLoadSuccess).