Skip to content

fix(plugins): multiple plugins (MIN-284)

mateusz-winiarczyk requested to merge MIN-284-multiple-plugins into development

Added the ability to load multiple instances of the same plugin. A mechanism for adding a number to the plugin name has been added when a given plugin is already loaded and we load another instance of the same plugin. If we do not have a plugin loaded without a prefix/without a number next to the name, the next instance will be loaded as such without a prefix/number. For example, we have 3 instances of the same plugin loaded, so we have the name "plugin", "plugin (1)", "plugin (2)". If we remove the "plugin" instance, the next loaded instance will be named "plugin" and not "plugin (3)".

Why mechanism of getting number is handled by storing occurrences in plugins manager and not taking active plugins from redux? When we load many plugins at once, e.g. when entering the url where the plugin hashes are, many scripts are launched at once in getInitPlugins, we invoke the script, but we have no way of tracking/controlling when PluginsManager.registerPlugin and store.dispatch(registerPlugin) are called and completed in it, therefore there is a race condition and if we took the number of loaded plugins from the store, e.g. several plugins could take the same number and therefore several plugins would have e.g. number 2 in their name. This is why we handle it in PluginsManager.registerPlugin as saving hashes as a hashMap synchronously, we can track the number of loaded plugins bypassing the race condition.

multiple-plugins

Closes MIN-284

Edited by mateusz-winiarczyk

Merge request reports